Skip to content
New issue

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

关于 ViewBox 组件scrollTo指定位置的问题 #2269

Closed
Tyrone2333 opened this issue Dec 2, 2017 · 5 comments
Closed

关于 ViewBox 组件scrollTo指定位置的问题 #2269

Tyrone2333 opened this issue Dec 2, 2017 · 5 comments

Comments

@Tyrone2333
Copy link

我在home组件的watch里观察$route对象,当 从列表到具体文章时保存之前的滚动距离,当从文章退回列表跳转到之前的位置.我将滚动距离保存在home组件的data里(home是一个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)
                }
            },
        },
`
@airyland
Copy link
Owner

airyland commented Dec 3, 2017

问题应该不在于这个函数,而在于内容渲染,建议你 setTimeout 执行。

@Tyrone2333
Copy link
Author

@airyland 是因为内容还没出来就滚动不到的原因?

@airyland
Copy link
Owner

airyland commented Dec 3, 2017

目测是,你可以测试一下

@Tyrone2333
Copy link
Author

@airyland setTimeout 延时0确实可以实现,但有个问题就是页面会一闪然后再到之前的位置

@airyland
Copy link
Owner

airyland commented Dec 4, 2017

这个一闪的问题建议对内容使用 keep-alive,activated 时设定滚动距离。参考 demo,并不会出现一闪的问题。

@airyland airyland closed this as completed Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants