We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我在home组件的watch里观察$route对象,当 从列表到具体文章时保存之前的滚动距离,当从文章退回列表跳转到之前的位置.我将滚动距离保存在home组件的data里(home是一个view-box嵌套router-view的组件).当我退回时使用this.$refs.viewBox.scrollTo(this.states.scrollTop)并不总是有效,经常都是回到顶部,请问这是怎么回事?
home
watch
$route
data
view-box
router-view
this.$refs.viewBox.scrollTo(this.states.scrollTop)
` watch: { $route(to, from) { let scrBody = this.$refs.viewBox.getScrollBody() let scrTop = this.$refs.viewBox.getScrollTop() // 从列表到具体文章时保存之前的滚动距离 if (to.name == "read_article" && from.name == "article") { console.warn("从列表到具体文章" + scrTop) this.states.scrollTop = scrTop } // 从文章退回列表跳转到之前的位置 if (to.name == "article" && from.name == "read_article") { console.warn("从文章退回列表 this.states.scrollTop: " + this.states.scrollTop) this.$refs.viewBox.scrollTo(this.states.scrollTop) } }, }, `
The text was updated successfully, but these errors were encountered:
问题应该不在于这个函数,而在于内容渲染,建议你 setTimeout 执行。
Sorry, something went wrong.
@airyland 是因为内容还没出来就滚动不到的原因?
目测是,你可以测试一下
@airyland setTimeout 延时0确实可以实现,但有个问题就是页面会一闪然后再到之前的位置
0
这个一闪的问题建议对内容使用 keep-alive,activated 时设定滚动距离。参考 demo,并不会出现一闪的问题。
No branches or pull requests
我在
home
组件的watch
里观察$route
对象,当 从列表到具体文章时保存之前的滚动距离,当从文章退回列表跳转到之前的位置.我将滚动距离保存在home
组件的data
里(home是一个view-box
嵌套router-view
的组件).当我退回时使用this.$refs.viewBox.scrollTo(this.states.scrollTop)
并不总是有效,经常都是回到顶部,请问这是怎么回事?The text was updated successfully, but these errors were encountered: