1.destoryed中我们可以销毁定时器,解绑全部指令及事件监听,清除全局事件等
mounted() { let self = this; window.onresize = () => { //监听窗口变化,重绘echarts return (() => { if (!!self.fansCome) { self.fansCome.resize(); } })() }; }, destroyed() { //页面销毁时需要清除全局的onresize事件,便面其他页面触发onresize事件中的方法 window.onresize = null; },
2.此时还能访问到页面是响应式数据和事件,也可以在这里注销eventBus等
beforeDestroy() { eventBus.$off('vipUpdate'); //页面销毁前注销该事件,避免vipUpdate事件的多次触发 }, mounted() { eventBus.$on('vipUpdate', () => { //声明一个vipUpdate的eventBus事件 this.openDialog(this.curTab); }) },