yangfeng
2024-03-29 82e27d0cadbddfc73e8b978e778b802dc8e51fa1
src/common/utils/request.ts
@@ -16,11 +16,12 @@
  (config) => {
    // 若是有做鉴权token , 就给头部带上token
    const token = getToken()
    if (token) {
      config.headers.Authorization = 'Bearer ' + token
    } else {
    if ((token == null || token == '' || token == 'undefined') && config.url != '/api/base/login') {
      router.push('/login')
      return config
      // window.location = `//${window.location.hostname}:9080`+'/login'
    } else if (token) {
      config.headers.Authorization = 'Bearer ' + token
    }
    return config
@@ -47,6 +48,10 @@
    }
  },
  (error) => {
    if (error.response.status === 401) {
      // alert('JWT失效,即将跳转至登录页..')
      router.push('/login')
    }
    let { message } = error
    if (message === 'Network Error') {
      message = '后端接口连接异常'