docs_vue2/app/router.scrollBehavior.js
2021-10-21 00:43:25 +08:00

24 lines
376 B
JavaScript

function timeout (t) {
return new Promise(resolve => {
setTimeout(resolve, t)
})
}
export default async function scrollBehavior (to) {
if (to.hash) {
// scroll to anchor by returning the selector
await timeout(0)
return {
selector: decodeURIComponent(to.hash),
offset: {
y: 120
}
}
}
return {
x: 0,
y: 0
}
}