最近有个需求,切换tag标签页面,重新激活此页面,滚动条位置不能变
思路就是在beforeRouteLeave中记录table的scrollTop,activated的时候重新设置scrollTop
activated() {
this.$nextTick(() => {
setTimeout(() => {
if (this.$refs.crud && this.$refs.crud.$refs && this.$refs.crud.$refs.table)
this.$refs.crud.$refs.table.setScrollTop(this.scrollTop)
}, 200)
})
},
beforeRouteLeave(to, from, next) {
if (from.path === '当前页面的路由') {
const table = this.$refs.crud && this.$refs.crud.$refs && this.$refs.crud.$refs.table
if (table && table.scrollBarRef) {
let scrollTop = table.scrollBarRef.wrapRef.scrollTop
this.scrollTop = scrollTop
}
}
next();
},