hookehuyr

代码优化

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