Vue异步更新DOM队列
export default {
data() {
return {
value: 123
}
},
watch: {
value(newValue) {
// 当changeValue事件触发,只会监听到一次
console.log(newValue) // 789
}
},
methods: {
changeValue() {
// Dom树的更新也是如此,避免重复的Dom渲染
this.value = 456 // watch无法监听
/* 如果一定要让watch监听到两次,可以使用
* $nextTick(() => {
* this.value = 789
* })
*/
this.value = 789 // watch可以监听
}
}
}