Vue.js - axios interceptor 中断请求继续执行方法

Ps:throw SyntaxError(),通过报错来斩断请求继续的问题,如下案例:

http.interceptor.response((response) => { /* 请求之后拦截器 */
  const res = response.data
  if (res && res.error && res.msg === 'xxx') { // 未登录调用接口或token过期或其他设备登录
    // 重新登录
    let userInfo = uni.getStorageSync('xxx')
    if (userInfo) {
      // 登录
      let info = JSON.parse(userInfo)
      user.login({
        'key1': info.accountMobile,
        'key2': info.time_stamp,
        'key3': info.userInfo ? info.userInfo.userOrgId : null
      }).then(res => {
        if (res.success) {
          // 登录成功 路由强制刷新
          // 保存用户数据到本地
          uni.setStorageSync('xxx', JSON.stringify(res.data))
          uni.navigateTo({url: ''})
          uni.navigateBack()
        } else {
          uni.reLaunch({
            url: '/xxx/xxx/xxx/login'
          })
          throw SyntaxError()
        }
      }).catch(error => {
        uni.reLaunch({
          url: '/xxx/xxx/xxx/login'
        })
        throw SyntaxError()
      })
    } else {
      uni.reLaunch({
        url: '/xxx/xxx/xxx/login'
      })
      throw SyntaxError()
    }
  } else if(res && res.error && res.msg === 'xxx') {
    uni.reLaunch({
      url: '/xxx/xxx/xxx/chooseOrg?login=1&limit=1'
    })
    throw SyntaxError()
  } else if(res && res.error && res.msg === 'xxx') {
    uni.reLaunch({
      url: '/xxx/xxx/xxx/chooseOrg?login=1&delete=1'
    })
    throw SyntaxError()
  }
  return response.data
})

你可能感兴趣的:(#,Vue.js)