一、 编程式导航

image.png
image.png

二、路由守卫

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()
      })
  }

错空隐没
16 声望0 粉丝

« 上一篇
js ms