[Feature] 新增页面切换进度条 (#1213)

新增页面切换进度条
This commit is contained in:
ipanghu
2022-09-06 10:17:05 +08:00
committed by GitHub
parent f606c7c891
commit b9a30b9ffe
4 changed files with 31 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import { useUserStore } from '@/pinia/modules/user'
import { useRouterStore } from '@/pinia/modules/router'
import getPageTitle from '@/utils/page'
import router from '@/router'
import Nprogress from 'nprogress'
let asyncRouterFlag = 0
@@ -37,6 +38,7 @@ async function handleKeepAlive(to) {
}
router.beforeEach(async(to, from) => {
Nprogress.start()
const userStore = useUserStore()
to.meta.matched = [...to.matched]
handleKeepAlive(to)
@@ -99,3 +101,13 @@ router.beforeEach(async(to, from) => {
}
}
})
router.afterEach(() => {
// 路由加载完成后关闭进度条
Nprogress.done()
})
router.onError(() => {
// 路由发生错误后销毁进度条
Nprogress.remove()
})