this.$nextTick()
-
用法:
在下次DOM更新循环之后执行回调。在修改数据之后立即使用它,然后等待DOM更新。
-
案例:
<template>
<div class="contentDiv">
<plan-one ref="planOne" ></plan-one>
</div>
</template>
<script>
import planOne from 'xxxxx'//引入组件
export default {
//注册组件
components:{
planOne,
},
mounted(){
//有可能组件planOne还未渲染dow就走了这个事件就会报undefined的错误,为了解决这种问题,于是乎vue就有了this.$nextTick()的用法。
this.$nextTick(()=>{
this.$refs.planOne.xxx()//xxx:事件名称
})
}
}
</script>