You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import axios from "axios";
|
|
|
|
|
|
|
|
|
|
const service = axios.create({
|
|
|
|
|
// process.env.NODE_ENV === 'development' 来判断是否开发环境
|
|
|
|
|
// easy-mock服务挂了,暂时不使用了
|
|
|
|
|
// baseURL: '',
|
|
|
|
|
// timeout: 5000
|
|
|
|
|
baseURL: "api", //把原来的项目地址,改成api,解决跨域问题
|
|
|
|
|
timeout: 30000
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
service.interceptors.request.use((config) => {
|
|
|
|
|
if(localStorage.getItem('token')){
|
|
|
|
|
config.headers.sessionId = localStorage.getItem('token')
|
|
|
|
|
}
|
|
|
|
|
return config;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
service.interceptors.response.use(
|
|
|
|
|
(response) => {
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
|
|
|
|
Promise.reject();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
return Promise.reject();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default service;
|