<div id="app">
<p ref="a">{{a}}</p>
<button @click="foo">change</button>
</div>
<script>
var app = new Vue({
el: "#app",
data: {
a: 333
},
methods: {
foo() {
this.a = this.a+1;
Vue.nextTick().then(function () {
console.log(app.$refs.a.innerHTML);
})
console.log(app.$refs.a.innerHTML);
}
}
})
</script>
点击后输出:
333 //在视图更新前就输出了
334 //在视图更新后才输出
网友评论