api.js总是冲突怎么办?
程序员文章站
2022-07-05 21:57:14
config.demo.js//copy至同目录config.local.js下,生效export default { // host :'http://192.168.8.47:9090', host: 'http://139.129.116.82:8080', // host: 'http://139.129.240.162:8080', // host :'http://47.240.97.96:8080',};config.demo.js 忽略提交可以在本地更改请求服务地....
config.demo.js
//copy至同目录config.local.js下,生效
export default {
// host :'http://192.168.8.47:9090',
host: 'http://139.129.116.82:8080',
// host: 'http://139.129.240.162:8080',
// host :'http://47.240.97.96:8080',
};
config.demo.js 忽略提交可以在本地更改请求服务地址
export default {
// host: 'https://bops.yoycol.com',
host: 'http://139.129.116.82:8080',
// host: 'http://139.129.240.162:8080',
// host :'http://47.240.97.96:8080',
};
# 忽略提交
config.local.js
api.js
import globalConfig from '@/config';
const {
host,
} = globalConfig;
export const base = host;
const service = axios.create({
baseURL: base + '/api',
timeout: 300 * 1000,
});
// 请求拦截器
service.interceptors.request.use(config => {
let token = localStorage.getItem('tokenId');
if (token) {
config.headers['Authorization'] = token;
}
config.paramsSerializer = x => {
// console.log(x);
return qs.stringify(x, {
arrayFormat: 'repeat',
});
};
return config;
});
/* 响应拦截器 */
service.interceptors.response.use(
function (response) {
// ①10010 token过期(30天) ②10011 token无效
if (
response.data.code === '100000' ||
response.headers['content-type'] === 'application/octet-stream' ||
response.headers['content-type'] === 'application/vnd.ms-excel;charset=UTF-8'
) {
return response.data;
} else {
if (response.data.code === '100015') {
localStorage.removeItem('tokenId');
window.location.href = '#/login';
} else {
// 判断token是否存在,如果存在说明需要更新token
// localStorage.setItem('tokenId', data.token );
Message.error(response.data.msg);
}
}
return Promise.reject(response);
},
function (error) {
return Promise.reject(error);
},
);
export const getOrderList = params => {
return service.post(`/trade/process/list`, params)
};
export const getViewGoods = params => {
return service
.get(`/product/spu/edit`, {
params,
})
};
本文地址:https://blog.csdn.net/weixin_44860425/article/details/108127799
上一篇: CentOS之安装JDK