网络日志

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