如何使用axios序列化参数 [英] how to serialize parameters using axios

查看:1180
本文介绍了如何使用axios序列化参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何序列化与 axios 一起使用的url参数?我的参数只是数组[1,2]中的数字.到目前为止,这是我的代码

How would I serialize url parameters for use with axios? My parameters are just numbers in array [1,2]. Here is my code so far

     axios({
       method: 'delete',
       url: '/api/'
     }) 

我的请求网址将是这样的 http://127.0. 0.1:8000/api/?id = 1& id = 2

My request url will be something like this http://127.0.0.1:8000/api/?id=1&id=2

我看了axios的paramsSerializer方法,但是它如何使用或使它迷惑不解.请指教.谢谢

I looked at the paramsSerializermethod that axios has but its confusing how it can be used or whether its even appropriate in my case. Please advice. Thanks

推荐答案

axios.getconfig对象接受params.在params中,您可以指定数组,它将为您进行转换.

the config object of axios.get accepts params. In params you can specify your array and it will do the conversion for you.

这里是一个例子:

axios.get('/api/', {
  params: {
   id: [1,2]
  }
}) 

这将发出如下请求:

/api/?id[]=1&id[]=2

这篇关于如何使用axios序列化参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆