@@ -2,7 +2,7 @@
|
||||
|
||||
// 引入 uni-ajax 模块
|
||||
import ajax from '@/uni_modules/u-ajax'
|
||||
|
||||
import store from '@/store/index.js';
|
||||
// 创建请求实例
|
||||
const instance = ajax.create({
|
||||
// 初始配置
|
||||
@@ -11,7 +11,10 @@ const instance = ajax.create({
|
||||
|
||||
// 添加请求拦截器
|
||||
instance.interceptors.request.use(
|
||||
config => {
|
||||
config => {
|
||||
if (store.getters.getuserIsLogin) {
|
||||
config.header['token'] = store.state.user.token
|
||||
}
|
||||
// 在发送请求前做些什么
|
||||
return config
|
||||
},
|
||||
@@ -25,12 +28,14 @@ instance.interceptors.request.use(
|
||||
instance.interceptors.response.use(
|
||||
response => {
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
let res = response.data;
|
||||
if (res.hasOwnProperty('token'))
|
||||
uni.setStorageSync('token', res.token);
|
||||
return response.data
|
||||
}
|
||||
}
|
||||
// 对响应数据做些什么
|
||||
console.log(response)
|
||||
|
||||
|
||||
return response.data
|
||||
},
|
||||
error => {
|
||||
|
||||
Reference in New Issue
Block a user