const install = (Vue, vm) => {
|
// 请求拦截器
|
uni.$u.http.interceptors.request.use((config) => {
|
uni.showLoading({
|
title: '加载中',
|
mask: true
|
});
|
// const Headtoken = vm.$store.state.token || ''
|
// if (Headtoken) {
|
// config.header['eva-auth-token'] = Headtoken;
|
// }
|
return config
|
}, config => {
|
return Promise.reject(config)
|
})
|
|
// 响应拦截器
|
uni.$u.http.interceptors.response.use((response) => {
|
uni.hideLoading();
|
// 登录过期
|
// if (response.data.code === 401) {
|
// uni.navigateTo({
|
// url: '/packageA/loginAgain/loginAgain'
|
// });
|
// }
|
if (response.data.code !== 200) {
|
uni.showToast({
|
title: response.data.message,
|
icon: "none",
|
duration: 2000
|
});
|
}
|
return response.data;
|
}, (response) => {
|
uni.hideLoading();
|
return Promise.reject(response)
|
})
|
}
|
|
export default { install }
|