和小程序很像,會小程序理解vue就會很快。
比較複雜的是監聽屬性,其中 @click = "counter--"
居然實現了自減。
<div id = "test">
<p>數字: {{ counter }}</p>
<button @click = "counter--">點擊</button>
</div>
<script type = "text/javascript">
var vm = new Vue({
el: '#app',
data: {
counter: 1
}
});
vm.$watch('counter', function(val1, val2) {
alert(val1 + ' 變爲 ' + val2);
});
</script>
v-model
可以在js代碼中用data更改輸入框的值。
<input type = "text" v-model = "xxx">
data: {
xxx:233
},
雖說我對前端不感冒,但這玩意比JQ好用是事實。