这里分享3.0和2.0 的方法对比
nexttick 是将回调推迟到下一个 dom 更新周期之后执行。
在更改了一些数据以等待 dom 更新后立即使用它
vue3.0
1、引入
import { nexttick } from 'vue'2、具体使用,配合异步
setup() {
const message = ref('hello!')
const changemessage = async newmessage => {
message.value = newmessage
await nexttick()
console.log('now dom is updated')
}
}3、具体使用,普通
方法里:
setup () {
let otherparam = reactive({
showa:false
})
nexttick(()=>{
otherparam.showa = true
})
return {
otherparam
}
}页面上:
<a-boo v-if="otherparam.showa"></a-boo>
vue2.0
this.abc = false
this.$nexttick(() => {
//你要执行的方法
this.abc = true
})总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论