嵌套路由简易写法
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
网友评论