12_computed.html 922 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./js/vue.js"></script>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <h1>
  12. {{num1}} + {{num2}} = {{sum}}
  13. </h1>
  14. <button @click="changeFun">change</button>
  15. </div>
  16. <script>
  17. let app = new Vue({
  18. el: '#app',
  19. data:{
  20. num1:1,
  21. num2:2
  22. },
  23. methods: {
  24. changeFun:function(){
  25. this.num2 = 100;
  26. }
  27. },
  28. computed:{
  29. sum:function(){
  30. console.log("computed运行")
  31. let thisSum = this.num1 + this.num2;
  32. return thisSum;
  33. }
  34. }
  35. })
  36. </script>
  37. </body>
  38. </html>