【问题标题】:Axios: How to send Params as Query StringAxios:如何将参数作为查询字符串发送
【发布时间】:2019-04-09 22:28:16
【问题描述】:

这是我的代码的基础

    const params = {
            contractId: data.contractId,
            notificationEmail: data.notificationEmail,
            userNumber: data.userNumber
    }

    axios.put(update_user_url, params, {
            headers: {
                Authorization: `Bearer ${authToken}`
            }
        }).then(blablabla....)

但是 Axios 在正文中发送 contractId、email 和 User 字段,而不是作为查询字符串。如何让它发送一个查询字符串?

【问题讨论】:

    标签: httprequest axios put http-request-parameters


    【解决方案1】:
    axios.put(
       `${base_url}/user`,
         null,
         {
            params: params,
            headers: {
              Authorization: token
            }
         }
    );
    

    检查documentation

    【讨论】:

    • 没有比自己编写查询字符串更优雅的方法吗? Axios 不能帮我做吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2014-06-29
    • 1970-01-01
    • 2012-05-12
    • 2020-04-16
    相关资源
    最近更新 更多