40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import axios from 'axios';
|
||
import ArtSystem from '../artSystem';
|
||
|
||
const service = axios.create({
|
||
baseURL: '/api', //api 的 base_url,根据开发生产环境配置文件配置
|
||
withCredentials: true, // 跨域请求时发送 cookies
|
||
timeout: 0,
|
||
headers: {
|
||
'Content-Type': 'application/json;charset=UTF-8',
|
||
},
|
||
responseType: 'json',
|
||
});
|
||
//axiios的response封装不在本库中,由各自引用CellsysArt的项目里去按需封装
|
||
service.interceptors.request.use(
|
||
(config) => {
|
||
let url = config.url;
|
||
let token = ArtSystem.token;
|
||
if (token && !config.headers['Authorization']) {
|
||
config.headers['Authorization'] = 'Bearer ' + token;
|
||
}
|
||
return config;
|
||
},
|
||
(error) => {
|
||
console.log(error);
|
||
return Promise.reject(error);
|
||
},
|
||
);
|
||
|
||
const post = (url, data, config) => {
|
||
return service.post(url, data, config);
|
||
};
|
||
|
||
const get = (url, data) => {
|
||
return service.get(url, {
|
||
params: data,
|
||
});
|
||
};
|
||
|
||
export { post, get, service };
|