Vue 记事

2019-04-04  本文已影响0人  Passon_Fang

嵌套路由简易写法

component: {render: h => h("router-view")}

Vue setInterval 使用

data(){
  return{
    timer: null,
  }
}

//
methods:{
  startTimer(){
    this.timer = setInterval(()=>{
      // do something
    }, 1000);
  },
  stopTimer(){
    if (this.timer) {
      clearInterval(this.timer);
    }
  }
},
beforeDestroy(){
  this.stopTimer();
}

Vue 组件中添加监听

添加监听: handleGlobalClick 属于 methods

  mounted() {
    document.addEventListener("click", this.handleGlobalClick);
  },

取消监听:

  beforeDestroy() {
    document.removeEventListener("click", this.handleGlobalClick);
  }

参考:https://github.com/iview/iview/blob/2.0/src/components/affix/affix.vue

上一篇 下一篇

猜你喜欢

热点阅读