1、問題
當我們需要通過get方式傳遞一個數(shù)組作為參數(shù) tag:[1,2,3,4]
預(yù)期是解析為:https://www.cnblogs.com/enter?tag=1&tag=2&tag=3&tag=4
然而真相是這樣的:https://www.cnblogs.com/enter?tag[]=1&tag[]=2&tag[]=3&tag[]=4,后臺是不可能解析到傳遞的參數(shù)
2、解決方案
此時需要將參數(shù)序列化,在axios中的配置如下
import?qs?from?'qs';
axiosInstance.interceptors.request.use(
??config?=>?{
????if?(config.method?===?'get')?{
??????config.paramsSerializer?=?function(params)?{
????????return?qs.stringify(params,?{?arrayFormat:?'repeat'?})
??????}
????}
}
3、參考鏈接
https://www.cnblogs.com/kingreatwill/p/12641238.html#/cnblog/works/article/12641238
https://blog.csdn.net/sansan_7957/article/details/82227040