likes
comments
collection

vue router

作者站长头像
站长
· 阅读数 4

一、 编程式导航

vue routervue router

二、路由守卫

beforeRouteEnter(to: any, from: any, next: any) {
    const obj = localStorage.supervisionUserInfo
      ? JSON.parse(localStorage.supervisionUserInfo)
      : {}

    const { auditStatus } = obj

    if (auditStatus !== 1) {
      next('/limit')

      return
    }
    next()
  }
 beforeRouteEnter(to: any, from: any, next: any) {
    API.getAuditStatus(this, {})
      .then((res: any) => {
        const { auditStatus } = res.data
        localStorage.setItem(
          'supervisionUserInfo',
          JSON.stringify({ ...res.data })
        )
        if (auditStatus === 1) {
          next('/')
        } else {
          next()
        }
      })
      .catch(() => {
        next()
      })
  }