路由拦截

router.beforeEach

router.beforeEach((to: any, from: any, next: any) => {

  // console.log(to.path)
  // const token = to.query.token || ''
  // if (token !== '') {
  //   localStorage.setItem('DingToken', token)
  // }
  const { permissions } = store.state
  console.log('permissions',permissions)
  if (permissions.length > 0) {
    const { meta } = to
    const index = permissions.findIndex((item: any) => {
      return item === meta.permissionsCode
    })
    if (meta.permissionsCode && index !== -1) {
      next()

      return
    } else if (to.path !== '/default') {
      if (meta.noVerify) {
        next()
      } else {
        Message.error('无权限!')
        next('/')
      }
    } else if (to.path === '/default') {
      next()
    }
  } else {
    next()
  }

  return
})

你可能感兴趣的:(vue.js)