gdpaoup
This commit is contained in:
@@ -3,8 +3,8 @@ const install = (Vue, vm) => {
|
||||
Vue.prototype.$u.http.setConfig({
|
||||
baseUrl: 'https://dmmall.sdbairui.com/api',
|
||||
loadingText: '努力加载中~',
|
||||
loadingTime: 800
|
||||
|
||||
loadingTime: 800,
|
||||
// originalData: true
|
||||
});
|
||||
|
||||
// 请求拦截,配置Token等参数
|
||||
@@ -17,6 +17,28 @@ const install = (Vue, vm) => {
|
||||
return config;
|
||||
|
||||
}
|
||||
|
||||
// 响应拦截,如配置,每次请求结束都会执行本方法
|
||||
Vue.prototype.$u.http.interceptor.response = (res) => {
|
||||
if(parseInt(res.errCode) == 0) {
|
||||
// res为服务端返回值,可能有errCode,result等字段
|
||||
// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
|
||||
// 如果配置了originalData为true,请留意这里的返回值
|
||||
return res;
|
||||
} else if(res.errCode == 401) {
|
||||
// 假设201为token失效,这里跳转登录
|
||||
vm.$u.toast('验证失败,请重新登录');
|
||||
setTimeout(() => {
|
||||
// 此为uView的方法,详见路由相关文档
|
||||
vm.$u.route('/pageA/login/login')
|
||||
}, 1500)
|
||||
return false;
|
||||
} else {
|
||||
// 如果返回false,则会调用Promise的reject回调,
|
||||
// 并将进入this.$u.post(url).then().catch(res=>{})的catch回调中,res为服务端的返回值
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user