axios.js
646 Bytes
import axios from 'axios';
import { message } from 'antd';
class Api {
constructor() {
this.api = axios.create({
timeout: 5000,
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
}
handelResult(res) {
let data = res.data || {};
if (data.code !== 200) {
message.error(data.message || '网络异常,请稍后重试');
}
return data;
}
get(...args) {
return this.api.get(...args).then(this.handelResult);
}
post(...args) {
return this.api.post(...args).then(this.handelResult);
}
}
export default new Api();