valaxy-theme-sakura
Version:
<h1 align="center">valaxy-theme-sakura</h1> <pre align="center"> 一个简单、个性化、可爱的动漫风格博客主题 ❥(ゝω・✿ฺ) </pre>
31 lines (26 loc) • 753 B
text/typescript
import type { Router } from 'vue-router'
import { scrollTo } from 'valaxy'
import { nextTick } from 'vue'
import { useSakuraAppStore } from '../stores'
export function toScrollPosition(router: Router) {
const sakuraAppStore = useSakuraAppStore()
router.afterEach((to, from) => {
const savedPosition = sakuraAppStore.getScrollPosition(to.path)
if (to.fullPath !== from.fullPath && !to.hash) {
nextTick(() => {
setTimeout(() => {
document.documentElement.scrollTop = savedPosition
}, 0)
})
}
})
router.beforeEach((to, from) => {
if (to.fullPath !== from.fullPath) {
nextTick(() => {
scrollTo(document.body, to.hash, {
smooth: true,
})
})
}
})
}