...
|
...
|
@@ -14,25 +14,31 @@ const errHandle = (error) => { |
|
|
message: '服务器开小差了~'
|
|
|
});
|
|
|
};
|
|
|
const request = (options) => {
|
|
|
return axios(options).then(res => res.data, errHandle);
|
|
|
const request = (options, store) => {
|
|
|
return axios(options).then((res) => {
|
|
|
if (res.data.code === 401) {
|
|
|
store && store.commit('needLogin', {needLogin: true});
|
|
|
return Promise.reject(res.data);
|
|
|
}
|
|
|
return res.data;
|
|
|
}, errHandle);
|
|
|
};
|
|
|
|
|
|
export const createApi = () => {
|
|
|
export const createApi = (context, store) => {
|
|
|
return {
|
|
|
get(url, params, options) {
|
|
|
return request(Object.assign({
|
|
|
url,
|
|
|
params,
|
|
|
method: 'get',
|
|
|
}), options);
|
|
|
}), options, store);
|
|
|
},
|
|
|
post(url, data, options) {
|
|
|
return request(Object.assign({
|
|
|
url,
|
|
|
data,
|
|
|
method: 'post',
|
|
|
}, options));
|
|
|
}, options), store);
|
|
|
}
|
|
|
};
|
|
|
}; |
...
|
...
|
|