1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>我的vue自学代码集</title> </head> <body> <div id="lesson-doubleBind"> <h4>{{ message}}</h4> <h2>json中字符串</h2> <h4>{{ message.str }}</h4> <input type="text" v-model="message.str"> <h2>json中数组</h2> <h4>{{ message.arr }}</h4> <input type="text" v-model="message.arr[0]"> <input type="text" v-model="message.arr[1]"> <input type="text" v-model="message.arr[2]"> <h2>json中二维数组</h2> <h4>{{ message.multiArray }}</h4> <input type="text" v-model="message.multiArray[0][0]"> <input type="text" v-model="message.multiArray[0][1]"> <h2>json中对象</h2> <h4>{{ message.obj }}</h4> <input type="text" v-model="message.obj.a"> <input type="text" v-model="message.obj.b"> <h2>一般数字</h2> <h4>{{ num }}</h4> <input type="text" v-model="num"> <h2>一般二维数组</h2> <h4>{{ multiArray }}</h4> <input type="text" v-model="multiArray[0][0]"> <button @click="submit1">后台改变数组变量</button> <button @click="submit2">后台改变一般变量</button> <button @click="submit3">后台改变对象变量</button> </div>
<script src="vue.min.js"></script> <script> new Vue({ el:'#lesson-doubleBind', data: { message:{ str: 'hello', arr : [1,2,3], multiArray: [[1,2],[3,4],[]], obj : { a : 1, b : 2 } }, num : 0, multiArray: [ [1,2], [3,4] ] }, watch: { message() { console.log(this.message) }, num() { console.log(this.num) }, multiArray() { console.log(this.multiArray) }
}, methods: { submit1 : function() { this.multiArray[0][0] -= 10; console.log(this.multiArray); }, submit2 : function() { this.str = "has changed"; console.log(this.str); }, submit3 : function() { this.message.str = "obj str has changed"; this.message.arr[0][0] -= 10; console.log(this.message); } } }); </script> </body> </html>
|