在router/index.js中增加scrollBehavior配置,具体代码如下:
const router = new VueRouter({
mode: "history",
routes,
scrollBehavior(to, from, savedPosition) {
if(savedPosition) {
return savedPosition
} else {
return {
x: 0,
y: 0
}
}
}
})