1.0.1 • Published 3 years ago

@lstmxx/axios-reflesh-token v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

axios-reflesh-token

封装axios,支持刷新token

install:

npm install @lstmxx/axios-reflesh-token --save

example:

const options = {
  config: {
    baseURL: '',
    timeout: 6000
  },
  requestInterceptors: function (config, getToken) {
    config.headers.Authorization = 'Bearer ' + getToken()
    return config
  },
  responseInterceptors: function (response) {
    const data = response.data
    const res = {
      status: data.code || response.status,
      data,
      msg: ''
    }
    res.msg = data.message || showStatus(res.status)
    return res
  },
  reflashTokenConfig: {
    url: '',
    method: '',
    data: {
    }
  },
  getTokenFn: function (response, setToken) {
    if (response.data.code === 200) {
      setToken(response.data.data.token, response.data.data.tokenType)
      return true
    }
    return false
  }
}
const service = new Service(options)
1.0.1

3 years ago

1.0.0

3 years ago