Usually we use $emit to monitor the component life cycle, and the parent component receives events for notification.
子组件
export default {
mounted() {
this.$emit('listenMounted')
}
}
父组件
<template>
<div>
<List @listenMounted="listenMounted" />
</div>
</template>
In fact, there is a simple way to use @hook to monitor the component life cycle without any changes in the component. Similarly, created , updated
, etc. can also use this method.
<template>
<List @hook:mounted="listenMounted" />
</template>