如何使用axios序列化参数 [英] how to serialize parameters using 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 paramsSerializer
method that axios has but its confusing how it can be used or whether its even appropriate in my case. Please advice. Thanks
推荐答案
axios.get
的config
对象接受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屋!