由于页面来回切换,每次都要重新加载页面,使用<keep-alive>进行组件缓存,但是会对表格照成一定影响。解决:使用<keep-alive>特定的钩子函数
activated() {
this.$nextTick(() => {
this.$refs.table1.doLayout(); //解决表格错位
});
},
此外,防止切换到其他页面后,旧页面定时器仍在执行,需要用到beforeRouteLeave钩子函数去清除定时器。
beforeRouteLeave(to, from, next) {
// 清除定时器
clearInterval(this.timer);
next();
},