1.可以通过 watch 来响应数据的变化,后面的on是用来监听事件的变化
<div id = "app">
<p style = "font-size:25px;">计数器: {{ counter }}</p>
<button @click = "counter++" style = "font-size:25px;">点我</button> //点击计数器,出现按钮
</div>
<script type = "text/javascript">
var vm = new Vue({
el: '#app',
data: {
counter: 1
}
});
vm.$watch('counter', function(nval, oval) { //监听counter,nval为counter原来的值,oval为变化后的值
alert('计数器值的变化 :' + oval + ' 变为 ' + nval + '!'); //点击计数器,alert弹窗
});
</script>