Vue.nextTick( [callback, context] )
1、在下次 DOM 更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法,获取更新后的 DOM。
Vue.nextTick(() => {}) / this.$nextTick(() => {// 更新完成})
<template lang="html">
<div>
<span>{{msg}}</span>
</div>
</template>
<script>
export default {
data () {
return {
msg: '没有更新之前'
}
},
methods: {
updateMsg () {
this.msg = '更新完成'
console.log('aaa', this.$el.textContent) // 没有更新之前
this.$nextTick(() => {
console.log('bb', this.$el.textContent) // 更新完成
})
}
},
mounted () {
this.updateMsg()
}
}
</script>
<style lang="css">
</style>

浙公网安备 33010602011771号