// 此vm参数为页面的实例,可以通过它引用vuex中的变量
module.exports = (vm) => {
// 初始化请求配置
uni.$u.http.setConfig((config) => {
/* config 为默认全局配置*/
config.baseURL = '/'; /* 根域名 */
config.header = {
}
return config
})
// 请求队列
let requestList = []
// 是否正在刷新中
let isRefreshToken = false
// 请求拦截
uni.$u.http.interceptors.request.use(async (config) => { // 可使用async await 做异步操作
if (['DELETE'].includes(config.method)) {
config.header = {
...config.header,
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
}
config.header["Authorization"] = `Bearer ${uni.getStorageSync("accessToken")}`;
return config
}, config => { // 可使用async await 做异步操作
return Promise.reject(config)
})
// 响应拦截
uni.$u.http.interceptors.response.use(async (response) => {
if (response.data.msg === &
uniapp使用uview(luch-request),无痛刷新token
于 2022-10-05 17:32:19 首次发布