import Vue from 'vue';
|
import axios from 'axios';
|
import rejectReplay from "@/assets/js/tools/rejectReplay";
|
if(process.env.NODE_ENV == 'dev') {
|
// 跨域请求
|
axios.defaults.baseURL = 'http://localhost:8091/fg/';
|
axios.defaults.withCredentials = true; // 保持请求头
|
}
|
let skipUrls = ["Server_stateAction_action_getTimestamp"];
|
// 添加请求拦截器
|
axios.interceptors.request.use(function (config) {
|
// 防重放操作
|
let rejectReplayStr = rejectReplay();
|
let url = config.url;
|
let isIn = false;
|
for(let i=0; i<skipUrls.length; i++) {
|
let skipUrl = skipUrls[i];
|
if(skipUrl == url) {
|
isIn = true;
|
break;
|
}
|
}
|
if(!isIn) {
|
if(url.indexOf("?") == -1) {
|
url = url.trim()+"?"+rejectReplayStr;
|
}else {
|
url = url.trim()+"&"+rejectReplayStr;
|
}
|
}
|
config.url = url;
|
// 在发送请求之前做些什么
|
return config;
|
}, function (error) {
|
// 对请求错误做些什么
|
return Promise.reject(error);
|
});
|
|
// 添加响应拦截器
|
axios.interceptors.response.use(function (response) {
|
// 对响应数据做点什么
|
return response;
|
}, function (error) {
|
return Promise.reject(error);
|
});
|
|
Vue.prototype.$axios = axios;
|
|
export default axios;
|