zoukankan      html  css  js  c++  java
  • axios拦截器

    1.对于携带cookie,token的信息进行判断

    2.参数为接受到后台的返回数据,类似code状态值,判断后对于cookie或token进行统一处理

    axios.interceptors.request.use((config) => {
      if (Cookies.get('BJCSI_USER_LOGINKEY')) {
        const id = Cookies.get('BJCSI_USER_ID') - 0
        const loginKey = Cookies.get('BJCSI_USER_LOGINKEY')
        config.headers = {
          'Content-Type': 'application/x-www-form-urlencoded',
          'id': id,
          'loginKey': loginKey
        }
      }
      return config
    }, (err) => {
      return Promise.reject(err)
    })
    axios.interceptors.response.use(res => {
      const code = res.data.code
      if (code === 11) {
        console.log('登录过期重新登录')
        Cookies.remove('BJCSI_USER_LOGINKEY')
        Cookies.remove('BJCSI_USER_ID')
        window.location = '/'
      } else {
        return res
      }
    }, err => {
      let errResponse = err.response
      const errMsg = {'msg': code(errResponse.status)}
      if (err && errResponse) {
        return Promise.reject(errMsg)
      }
    })
  • 相关阅读:
    Document
    Document
    Document
    Document
    Document
    Document
    set常见操作:
    select 不存在字段,并设置默认值
    c#为字段设置默认值,以及构造函数初始化List对象。
    ThreadLocal
  • 原文地址:https://www.cnblogs.com/hurenjie/p/10516896.html
Copyright © 2011-2022 走看看