常规
<!-- Child -->
<script>
export default {
mounted () {
this.$emit('onMounted')
}
}
</script>
<!-- Parent -->
<template>
<Child @onMounted="handleOnMounted" />
</template>
@hook:mount
还有另一种简单的解决方案,你可以改用 @hook:mount
@hook:mount
<!-- Parent -->
<template>
<Child @hook:mounted="handleOnMounted" />
</template>