axios 发送formData参数

项目中遇到的,记录一下

普通post请求:

axios 发送formData参数

当需要发送formData格式的时候如下

//转换数据的方法
transformRequest: [
    function(data) {
        let ret = '';
        for (let it in data) {
            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
        }
        return ret;
    }
],
//设置请求头
headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
}

在发送请求的时候设置这个内容即可如下:

 axios 发送formData参数