import axios from "axios";
import { message } from "ant-design-vue";
/**
* 配置
* @type {AxiosInstance}
*/
const service = axios.create({
baseURL: "",
timeout: 0, //不限时
});
/**
* 请求头 设置 设置token, 'Content-Type' 等
*/
service.interceptors.request.use((config) => {
let cookie = 'JSESSIONID=52BD2D1609515CC49D2E53D15EEADF19; amt=80c69c20e1785e74dc35544c1ae59ff7; amu=wuyunxia; amuv1=wuyunxia; amtv1=11b37bf14d774650a60015c677e5346f';
if(cookie) {
// config.headers['Cookie'] = cookie;
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
return config;
},
(error) => {
return error;
});
/**
* 响应
*/
service.interceptors.response.use((response) => {
const res = response.data;
return res;
},
(error) => {
message.error(error);
return error;
});
export default service;
使用
import httpService from './httpService'
export const getApiQuery = ( param) => {
return httpService.get("url", {param})
};
export const postApiQuery = ( data) => {
return httpService.post("url", data)
};
在页面中调用
getApiQuery(data).then(res => {
console.log(res)
});