docs_vue2/app/router.scrollBehavior.js

24 lines
375 B
JavaScript
Raw Normal View History

2021-10-20 10:24:04 +08:00
function timeout (t) {
return new Promise(resolve => {
setTimeout(resolve, t)
})
}
export default async function scrollBehavior (to) {
2021-10-18 18:52:29 +08:00
if (to.hash) {
2020-08-13 11:47:56 +08:00
// scroll to anchor by returning the selector
2021-10-20 10:24:04 +08:00
await timeout(0)
2021-10-18 18:52:29 +08:00
return {
selector: decodeURIComponent(to.hash),
offset: {
y: 32
2021-10-18 18:52:29 +08:00
}
}
}
return {
x: 0,
y: 0
2020-08-13 11:47:56 +08:00
}
}