在一些場(chǎng)景中综看,我需要在父組件上知道子組件什么時(shí)候被創(chuàng)建崩掘、掛載或者是更新,特別是當(dāng)為原生 js 庫(kù)創(chuàng)建組件時(shí)立宜。
通過(guò)使用 @hook: 前綴監(jiān)聽(tīng)生命周期中的鉤子站叼,并指定回調(diào)函數(shù)
舉個(gè)例子,如果你想要在第三方組件 v-runtime-template 渲染時(shí)做一些事情课梳,那么你可以監(jiān)聽(tīng)它的生命周期中的 updated 鉤子
<v-runtime-template @hook:updated="doSomething" :template="template" />
image.png