vue监听生命周期

监听生命周期事件

  • 内部监听声明周期函数
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
posted @ 2020-11-02 16:13  baifangzi  阅读(562)  评论(0)    收藏  举报