axios get传递数组 paramsSerializer序列化
import axios from 'axios';
import qs from 'qs';
axios.create({
baseURL: process.env.baseUrl,
paramsSerializer: (params) => qs.stringify(params, { indices: false }),
})
qs.stringify({ids: [1, 2, 3]}, { indices: false })
//形式: ids=1&ids=2&id=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘indices‘})
//形式: ids[0]=1&aids1]=2&ids[2]=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘brackets‘})
//形式:ids[]=1&ids[]=2&ids[]=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘repeat‘})
//形式: ids=1&ids=2&id=3
// 用法
let params = { order_id: [1, 2, 3] }
axios.get('www.baidu.com', params); // www.baidu.com?order_id=1&order_id=2&order_id=3