新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)VUE3教程:Vue3.0組合式API生命周期鉤子
本指南假定你已經(jīng)閱讀了 組合式 API 簡介和響應(yīng)性基礎(chǔ)。如果你不熟悉組合式 API,請先閱讀這篇文章。
在 Vue Mastery 上觀看關(guān)于生命周期鉤子的免費(fèi)視頻
你可以通過在生命周期鉤子前面加上 “on” 來訪問組件的生命周期鉤子。
下表包含如何在 setup () 內(nèi)部調(diào)用生命周期鉤子:
| 選項(xiàng)式 API | Hook inside setup |
|---|---|
beforeCreate |
Not needed* |
created |
Not needed* |
beforeMount |
onBeforeMount |
mounted |
onMounted |
beforeUpdate |
onBeforeUpdate |
updated |
onUpdated |
beforeUnmount |
onBeforeUnmount |
unmounted |
onUnmounted |
errorCaptured |
onErrorCaptured |
renderTracked |
onRenderTracked |
renderTriggered |
onRenderTriggered |
TIP
因?yàn)?setup 是圍繞 beforeCreate 和 created 生命周期鉤子運(yùn)行的,所以不需要顯式地定義它們。換句話說,在這些鉤子中編寫的任何代碼都應(yīng)該直接在 setup 函數(shù)中編寫。
這些函數(shù)接受一個(gè)回調(diào)函數(shù),當(dāng)鉤子被組件調(diào)用時(shí)將會被執(zhí)行:
// MyBook.vue
export default {
setup() {
// mounted
onMounted(() => {
console.log('Component is mounted!')
})
}
} 網(wǎng)站欄目:創(chuàng)新互聯(lián)VUE3教程:Vue3.0組合式API生命周期鉤子
URL標(biāo)題:http://www.dlmjj.cn/article/cojcdod.html


咨詢
建站咨詢

