// Child.vue mounted() {this.$emit("mounted");} " >

久久久久久久视色_18人成视频网站网址_久久九九国外免费视频_a级女少妇bbw

Vue 中父組件可以監(jiān)聽(tīng)到子組件的生命周期

2020/11/27 18:06:50   閱讀:6382    發(fā)布者:6382
一、使用 on 和 emit
// Parent.vue
<Child @mounted="doSomething"/>
// Child.vue
mounted() {
  this.$emit("mounted");
}

二、使用 hook 鉤子函數(shù)
//  Parent.vue
<Child @hook:mounted="doSomething" ></Child>

doSomething() {
   console.log('父組件監(jiān)聽(tīng)到 mounted 鉤子函數(shù) ...');
},
//  Child.vue
mounted(){
   console.log('子組件觸發(fā) mounted 鉤子函數(shù) ...');
},
// 以上輸出順序?yàn)椋?br /> // 子組件觸發(fā) mounted 鉤子函數(shù) ...
// 父組件監(jiān)聽(tīng)到 mounted 鉤子函數(shù) ...