axios request processing parameter space, & translation issues

Method 1: Write a translation function yourself, replace characters such as &, spaces with corresponding characters, the specific replacement is as follows

Special characters Translated characters
+ % 2B
Space %20
/ % 2F
% 3F
% %25

Method 2: Use the configuration paramsSerializer provided by axios to configure it
when creating axios instance. All subsequent separate requests do not need to be configured repeatedly

 // 创建axios实例
 import Qs from 'qs'; 
var instance = axios.create({
    timeout: 1000 * 60,//请求超时
    paramsSerializer: function(params) {//序列化请求参数,避免get请求参数出现&,空格等识别错误的问题
        return Qs.stringify(params, {arrayFormat: 'brackets'})
    }
});

Guess you like

Origin blog.csdn.net/weixin_44494811/article/details/107611512