【问题标题】:How to properly convert json array in axios query parameter?如何在axios查询参数中正确转换json数组?
【发布时间】:2023-01-31 17:18:50
【问题描述】:

我很难用 axios 做一些看起来很简单的事情:

这是我的 axios 查询:

axios.get('/consumption_reports', {
    params: {
        exists: {
            energyDeliveryPoint : false
        }
     }
})

结果是这个查询:

consumption_reports?exists={"energyDeliveryPoint":false}

当我想要这个结果时:

consumption_reports?exists[energyDeliveryPoint]=false

我尝试了许多不同的解决方案,但找不到有效的解决方案。
我期待任何使代码简单的答案。
PS:我不想用我想要的行为对 url 进行硬编码。

【问题讨论】:

    标签: javascript json axios


    【解决方案1】:

    我终于找到了自己,在那种情况下我别无选择:

    axios.get('/consumption_reports', {
        params: {
            "exists[energyDeliveryPoint]": false
        }
    })
    

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 2020-05-10
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多