1234567891011121314151617181920212223242526272829303132333435363738 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <script src="./js/vue.js"></script>
- </head>
- <body>
- <div id="app">
- <h1>
- {{num1}} + {{num2}} = {{sum}}
- </h1>
- <button @click="changeFun">change</button>
- </div>
- <script>
- let app = new Vue({
- el: '#app',
- data:{
- num1:1,
- num2:2
- },
- methods: {
- changeFun:function(){
- this.num2 = 100;
- }
- },
- computed:{
- sum:function(){
- console.log("computed运行")
- let thisSum = this.num1 + this.num2;
- return thisSum;
- }
- }
- })
- </script>
- </body>
- </html>
|