hookehuyr

代码优化

......@@ -2,7 +2,7 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-28 10:17:40
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-30 01:16:40
* @LastEditTime: 2022-06-30 01:30:26
* @FilePath: /tswj/src/utils/axios.js
* @Description:
*/
......@@ -24,13 +24,11 @@ axios.interceptors.request.use(
// const url_params = parseQueryString(location.href);
// GET请求默认打上时间戳,避免从缓存中拿数据。
const timestamp = config.method === 'get' ? (new Date()).valueOf() : '';
if (config.method === 'post') {
// 上传相关接口需要屏蔽掉封装, 不能序列化,数据会报错。
if (!strExist(['a=upload', 'upload.qiniup.com'], config.url)) {
// POST PHP需要修改数据格式
config.data = qs.stringify(config.data)
}
}
/**
* POST PHP需要修改数据格式
* 序列化POST请求时需要屏蔽上传相关接口,上传相关接口序列化后报错
*/
config.data = config.method === 'post' && !strExist(['a=upload', 'upload.qiniup.com'], config.url) ? qs.stringify(config.data) : config.data;
// 绑定默认请求头
config.params = { ...config.params, timestamp }
return config;
......