zoukankan      html  css  js  c++  java
  • vue中axios.post的复杂参数传参不支持的解决办法

    我的参数格式是这样的,经过测试传到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
    });
    }
    });
    
    
    
     
  • 相关阅读:
    校验输入框输入两位小数
    限制输入框只能输入整数
    npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
    yum -y wget
    docker 安装mysql
    centos 安装docker
    VirtualBox安装CentOS系统
    Spring Cloud服务保护
    从零开始搭建系统2.8——HDFS安装及配置
    从零开始搭建系统4.3——详细设计
  • 原文地址:https://www.cnblogs.com/BARNEYROSS/p/15137736.html
Copyright © 2011-2022 走看看