/**
- @module tabsKeepAlive
- @author: huoyou
- @description: mescroll 缓存处理
*/
export default {
// mescrollType-1 普通mescroll
// mescrollType-2 带tabs的mescroll
mounted () {
if (this.KaTeX parse error: Expected 'EOF', got '&' at position 22: …meta.keepAlive &̲& this.mescroll…refs.swiperTabs) {
const { curIndex } = this. r e f s . s w i p e r T a b s c o n s t t i m e r = s e t T i m e o u t ( ( ) = > t h i s . t a b s [ c u r I n d e x ] . m e s c r o l l . s c r o l l T o ( 0 , 0 ) / / 初 始 化 滚 动 条 位 置 , 0 ) t h i s . refs.swiperTabs const timer = setTimeout(() => { this.tabs[curIndex].mescroll.scrollTo(0, 0) // 初始化滚动条位置 }, 0) this. refs.swiperTabsconsttimer=setTimeout(()=>this.tabs[curIndex].mescroll.scrollTo(0,0)//初始化滚动条位置,0)this.once(‘hook: beforeDestroy’, () => {
clearTimeout(timer)
})
}
}
},
activated () {
if (this.KaTeX parse error: Expected 'EOF', got '&' at position 22: …meta.keepAlive &̲& this.mescroll…route.meta.scrollTop || 0
if (this.KaTeX parse error: Expected '}', got 'EOF' at end of input: …Index } = this.refs.swiperTabs
if (scrollTop !== 0) {
this.tabs[curIndex].mescroll.scrollTo(scrollTop, 0) // 滚动到缓存的位置
}
}
}
},
beforeRouteLeave (to, from, next) {
if (from.meta.keepAlive) { // keepAlive=true为前提
const arr = (from.meta && from.meta.whiteKeepAlive) || []
if (this.mescrollType === 2) {
if (this.KaTeX parse error: Expected '}', got 'EOF' at end of input: …Index } = this.refs.swiperTabs
this.tabs[curIndex].mescroll.hideTopBtn()
}
}
if (!arr.includes(to.path)) {
this.KaTeX parse error: Expected 'EOF', got '}' at position 43: … from.name) }̲ else { if…refs.swiperTabs) {
const { curIndex } = this.$refs.swiperTabs
from.meta.scrollTop = this.tabs[curIndex].mescroll.getScrollTop() // 缓存 滚动的位置到 meta.scrollTop
}
}
}
}
next()
}
}
路由中写代码如下
{
path: ‘/xxxxxxxxx’,
name: ‘xxxxxxxxxxxx’,
meta: {
keepAlive: true,
whiteKeepAlive: [’/wisdom-analysis/subpage’] // 进入以下页面后再进入该页面,页面不刷新
},
component: () => import(’@/views/wisdom-analysis/wisdom.vue’)
},
保证name与页面name的一致性