关于javascript:vue中destroyed方法的使用

5次阅读

共计 566 个字符,预计需要花费 2 分钟才能阅读完成。

  1. // 移除监听事件
    destroyed() {

     window.removeEventListener('resize', this.resizeWin)

    }

  2. // 移除对 dom 的操作
    destroyed() {

     $("body").removeClass('maven-select');

    }

  3. // 因为 EventBus 不会凭空隐没,所以须要销毁 EventBus 相干定义的事件,否则始终会以指数型形式触发 $emit
    destroyed() {

     bus.$off('get', this.myhandle)

    }

  4. // 销毁 VueX 中存储的数据,否则页面不刷新,在页面刚渲染时,始终展现的是上次的数据
    destroyed() {

     this.$store.dispatch("cleartList");

    }

  5. // 清空浏览器 localStorage 种植的某些变量
    destroyed() {

     window.localStorage.removeItem("ID");

    }

  6. // 销毁定时器
    destroyed() {

     clearInterval(this.timer);
     this.timer = null;

    }

  7. // beforeDestroy 移除 echarts 的所有鼠标事件以及清空会话
    beforeDestroy() {

     this.chartDom.off('click');
     this.chartDom.clear();

    }

正文完
 0