Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
前端:router.beforeEach使用async写法替代promise写法
  • Loading branch information
4linuxfun committed Feb 29, 2024
commit c523624feae784459e1659e55b5c35c6960fa885
18 changes: 9 additions & 9 deletions www/src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {useTabsStore} from '@/stores/tabs'

const whiteList = ['/login'] // no redirect whitelist

router.beforeEach((to) => {
router.beforeEach(async (to) => {
const store = useStore()
const {tabAdd} = useTabsStore()
console.log('start before each')
console.log('start before each', to)

if (getToken()) {
console.log('已经有token')
Expand All @@ -27,23 +27,23 @@ router.beforeEach((to) => {
// router.push('/')
if (store.asyncRoutes.length === 0) {
console.log('asyncroutes is not set')
store.getInfo().then(() => {
return store.getPermission()
}).then(() => {
let asyncRoutes = makeRouter(store.asyncRoutes)
try {
await store.getInfo()
await store.getPermission()
let asyncRoutes = await makeRouter(store.asyncRoutes)
console.log(asyncRoutes)
for (let route of asyncRoutes) {
console.log('add route:')
console.log(route)
router.addRoute('home', route)
}
return {path: to.fullPath, replace: true}
}).catch((err) => {
console.log('用户权限拉取失败' + err)
} catch (e) {
console.log('用户权限拉取失败' + e)
store.logOut().then(() => {
location.reload()
})
})
}
}
console.log('当前生效路由表')
console.log(router.getRoutes())
Expand Down