vue hook 妙用

export default{
  methods:{
    fn(){
      const timer = setInterval(()=>{
        //具体执行代码
        console.log('1');
      },1000);
      this.$once('hook:beforeDestory',()=>{
        clearInterval(timer);
        timer = null;
      })
    }
  }
}

  

//父组件
<rl-child
  :value="40"
  @hook:mounted="childMountedHandle"
/>
method () {
  childMountedHandle() {
  // do something...
  }
},

  

posted @ 2021-03-08 11:28  一直闭眼看世界  阅读(65)  评论(0编辑  收藏  举报