123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <div id="app">
- <button @click="change()">修改</button>
- <h2>姓: {{firstName}}</h2>
- <h2>名: {{lastName}}</h2>
- <h2>全称: {{fullName}}</h2>
- </div>
- <script src="vue.js"></script>
- <script>
- new Vue({
- el:"#app",
- data:{
- firstName: 'zhang',
- lastName: 'san'
- },
- methods:{
- change(){
- this.firstName = 'li'
- }
- },
- watch:{
- firstName: function(){
- console.log(111)
- },
- lastName: function(){
- console.log(222)
- }
- },
- computed:{
- fullName: function(){
- return this.firstName + this.lastName
- }
- }
- })
- </script>
- </body>
- </html>
|