vue3.0中使用nextTick


vue3.0


前言:
這里分享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
})

 


原文鏈接:https://blog.csdn.net/qq_41619796/article/details/118996974


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM