首页 > 移动平台 > 详细

vue中axios.post的复杂参数传参不支持的解决办法

时间:2021-08-13 17:10:32      阅读:16      评论:0      收藏:0      [点我收藏+]
我的参数格式是这样的,经过测试传到api中不能被正确接收:
let data = [{
                            Field: "CreateTime",
                            Operator: ">=",
                            Value: _this.beginTime
                        },
                        {
                            Field: "CreateTime",
                            Operator: "<=",
                            Value: _this.endTime
                        },
                        {
                            Field: "PatientId",
                            Operator: "=",
                            Value: _this.dynamicTags.join(‘,‘)
                        },
                        {
                            Field: "TaskName",
                            Operator: "=",
                            Value: value
                        },
                        {
                            Field: "LikeType",
                            Operator: "=",
                            Value: _this.radioLikeType
                        }];

 


通过在axios中转换一下,即可成功请求:

axios({
method: "post",
url: httpUrl + "/api/Original/PushMessage",
data: { "": data},
headers: {
‘Content-Type‘: ‘application/x-www-form-urlencoded‘, //指定消息格式
},
transformRequest: [function (e) {
// 数据转换的核心代码
function setDate(e) {
var t, n, i, r, o, s, a, c = "";
for (t in e)
if (n = e[t], n instanceof Array)
for (a = 0; a < n.length; ++a)
o = n[a], i = t + "[" + a + "]", s = {}, s[i] = o, c += setDate(s) + "&";
else if (n instanceof Object)
for (r in n) o = n[r], i = t + "[" + r + "]", s = {}, s[i] = o, c += setDate(s) + "&";
else void 0 !== n && null !== n && (c += encodeURIComponent(t) + "=" + encodeURIComponent(n) + "&");
return c.length ? c.substr(0, c.length - 1) : c
}
// 数据转换的核心代码结束
return setDate(e)
}]
}).then(res => {
if (res.data.message === ‘OK‘) {
this.$message({
type: ‘success‘,
message: res.data.data.message
});
} else {
this.$message({
type: ‘error‘,
message: res.data.data.message
});
}
});

 

 

 

vue中axios.post的复杂参数传参不支持的解决办法

原文:https://www.cnblogs.com/BARNEYROSS/p/15137736.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!