【发布时间】:2019-06-11 17:33:59
【问题描述】:
我有这样的路线:
{
path: '/kontakt',
redirect: '#contact',
component: index
},
和滚动行为:
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
}
if(!to.hash) {
return {
x: 0, y: 0
}
}
if(to.hash) {
return {
selector: to.hash
}
}
}
和 IMO,因为我在用户实际输入页面 1 秒后显示我的页面(我显示徽标 1 秒)当我输入 /kontakt 路由时,上面的代码不会将页面滚动到 #contact div。
app.vue
<div v-show="timeGap">
<router-view />
</div>
这里 timeGap 在 setTimeout 方法中 1 秒后更改为 true。如何修复,使其在此超时后滚动到#contact div?
【问题讨论】:
-
你能在 codepen 或类似的地方提供一个完整的例子吗?
-
无法通过代码游乐场内的路由真正重现整个 SPA。
-
您可以在 codepen +
setTimeout上创建Vue.js+vue-router示例或您正在使用的示例,这样会更好地找出问题所在。
标签: vue.js hash vuejs2 vue-router