1. 被keep-alive缓存的页面如果使用了cube-ui的scroll相关组件,必须在activated方法中手动调用scroll组件的refresh()方法刷新,否则会出现无法上下滚动的情况
2.被keep-alive缓存的页面如果使用了cube-ui的slide相关组件,必须在activated方法中手动调用slide组件的refresh()方法刷新,否则会出现tab标签切换后slide不滑动的情况。slide组件的refreshResetCurrent属性为false(当刷新时是否重置索引,false不重置)
示例代码 this.userStatusList = [‘空闲中’, ‘面试中’, ‘请假中’]
activated () {
// 被keep-alive缓存的页面如果使用了cube-ui的scroll相关组件,必须在activated方法中手动调用scroll组件的refresh()方法刷新,否则会出现无法上下滚动的情况
for (let i = 0; i < this.userStatusList.length; i++) {
let scrollStr = 'scroll_' + i.toString()
if (this.$refs[scrollStr]) {
this.$refs[scrollStr].refresh()
}
}
// 被keep-alive缓存的页面如果使用了cube-ui的slide相关组件,必须在activated方法中手动调用slide组件的refresh()方法刷新,否则会出现tab标签切换后slide不滑动的情况。slide组件的refreshResetCurrent属性为false(当刷新时是否重置索引,false不重置)
this.$refs.slide.refresh();
if (this.scrollHeight < 0) {
this.scrollHeight = this.scrollHeight + 30
}
// 滚动到之前浏览位置
for (let i = 0; i < this.userStatusList.length; i++) {
if (this.selectedLabel === this.userStatusList[i]) {
let scrollStr = 'scroll_' + i.toString()
this.$refs[scrollStr].scrollTo(0, this.scrollHeight)
}
}
},
deactivated (to, from, next) {
try {
// 组件销毁前获取滚动高度
// 如果是在浏览器中运行, 不需要手动记录滚动高度,将scroll/slide组件的属性observeDOM设为false即可
// 如果是在原生的webview中运行,必须手动记录滚到高度,并在activated方法中返回到手动记录的滚动高度
for (let i = 0; i < this.userStatusList.length; i++) {
if (this.selectedLabel === this.userStatusList[i]) {
let heightStr = ''
let scrollStr = 'scroll_' + i.toString()
if (this.$refs[scrollStr]) {
heightStr = this.$refs[scrollStr].pullDownStyle ? this.$refs[scrollStr].pullDownStyle : '0'
}
heightStr = heightStr.replace('top:', '')
heightStr = heightStr.replace('px', '')
heightStr = parseFloat(heightStr)
this.scrollHeight = heightStr
}
}
} catch (e) {
}
}