脚手架搭建
This commit is contained in:
40
src/api/httpServe.js
Normal file
40
src/api/httpServe.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import axios from 'axios'
|
||||
import QS from 'qs';
|
||||
|
||||
// 创建axios
|
||||
const service = axios.create({
|
||||
// baseURL: 'https://hd.xglpa.com/pars-training', //生产环境
|
||||
// baseURL: 'http://test.szxgl.cn/pars-training', //测试环境
|
||||
// withCredentials: true,
|
||||
baseURL: process.env.VUE_APP_API,
|
||||
// responseType: 'json',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// 添加请求拦截器
|
||||
service.interceptors.request.use(function (config) {
|
||||
// 在发送请求之前做些什么
|
||||
console.log("开始请求");
|
||||
config
|
||||
return config;
|
||||
}, function (error) {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
// 添加响应拦截器
|
||||
service.interceptors.response.use(function (response) {
|
||||
|
||||
|
||||
// 对响应数据做点什么
|
||||
// console.log(response.data);
|
||||
return response;
|
||||
}, function (error) {
|
||||
// 对响应错误做点什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
export default service;
|
||||
Reference in New Issue
Block a user