data() {
return {
monitor: null
};
},
mounted() {
this.monitor = setInterval(() => {
console.log("正在获取数据");
}, 1000);
this.$once("hook:beforeDestroy", () => { //beforeDestory时触发该事件
clearInterval(this.monitor);
});
},
<div id="app">
<my-map @hook:created="handleCreated" @hook:mounted="handleMounted" chartId="deviceChart"></my-map>
</div>
data() {
return {
isCur: true
};
},
methods: {
handleCreated() {
console.log(‘created‘)
},
handleMounted() {
console.log(‘mounted‘)
}
},
子组件created-->父组件created--->子组件mounted---->父组件mounted
原文:https://www.cnblogs.com/genhao7/p/13914987.html