nextTick
If we want to use DOM objects in Vue, we can use this method
this.$nextTick(() => {
// 这个函数会等待DOM执行完成后执行
})
this.$nextTick().then(() => {
// 这个函数会等待DOM执行完成后执行
})
ref
If we want to get the DOM object or component object, we can add the ref attribute to the corresponding tag and give it a custom name
<child ref="child"></child>
<!-- this.$refs.child 这个获取到的是一个组件对象 -->
<div ref="div"></div>
<!-- this.$refs.div 这个获取到的是一个DOM对象 -->
ref is best used in combination with nextTick