src/api/config
import axios from "axios";
// 创建一个axios实例
const service = axios.create({
timeout: 3000,
});
// 添加请求拦截器
service.interceptors.request.use(
(config) => config,
(err) => console.log(err)
);
// 添加响应拦截器
service.interceptors.response.use(
(response) => {
let res = {};
res.status = response.status;
res.data = response.data;
return res;
},
(err) => console.log(err)
);
export default service
main.js
import http from './api/config'
Vue.prototype.$http = http
网友评论