0
You can add a listener on the child component fom the parent. It would look like this:
Vue3
<Component
@vnodeMounted="handleMounted"
/>
Vue2
<Component
@hook:mounted="handleMounted"
/>
You can replace the hook name by the lifecycle one you want to listen to ! I guess it should be used sparsely as it is not present in the documentation and thus be an internal API that is not destined to be used directly.
source:
- [Vuejs]-Vue prop will pass through <router-view /> to child component 1, but not child component 2. Why?
- [Vuejs]-How to add a marker by clicking on the map in leaflet js on vue 3
0
Looks like there is a typo in the event name in the child component while triggering the event else code should work fine.
- It should be
is-child-mounted
instead ofischildmounted
- It should be
@is-child-mounted="childMounted = true"
instead of@is-child-mounted="childMounted"
Live Demo :
Vue.component('child', {
props: ['childmsg'],
template: '<p>{{ childmsg }}</p>',
mounted() {
this.$emit('is-child-mounted')
}
});
var app = new Vue({
el: '#app',
data: {
childMounted: false
},
mounted() {
if (this.childMounted) {
console.log('child mounted');
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<child childmsg="This is a child component" @is-child-mounted="childMounted = true"></child>
</div>
- [Vuejs]-Unable to read JSON Data from BigQuery and display it on the Vue Web Page (Nuxt 3 & Google BigQuery)
- [Vuejs]-Vue 2: Using router-link, but button stays on page?
Source:stackexchange.com