Skip to content

Commit

Permalink
feat: 参考axio源代码 添加支持paramsSerializer。
Browse files Browse the repository at this point in the history
  • Loading branch information
alwxkxk committed Feb 9, 2022
1 parent 99ee7fe commit cae1043
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mergeKeys = (keys, config2) => {
}
export default (config) => {
return new Promise((resolve, reject) => {
let fullPath = buildURL(buildFullPath(config.baseURL, config.url), config.params)
let fullPath = buildURL(buildFullPath(config.baseURL, config.url), config.params,config.paramsSerializer)
const _config = {
url: fullPath,
header: config.header,
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default {
header: {},
method: 'GET',
dataType: 'json',
paramsSerializer:null,
// #ifndef MP-ALIPAY
responseType: 'text',
// #endif
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/mergeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default (globalsConfig, config2 = {}) => {
let config = {
baseURL: config2.baseURL || globalsConfig.baseURL || '',
method: method,
paramsSerializer:config2.paramsSerializer || globalsConfig.paramsSerializer,
url: config2.url || '',
params: config2.params || {},
custom: {...(globalsConfig.custom || {}), ...(config2.custom || {})},
Expand Down
6 changes: 4 additions & 2 deletions src/lib/helpers/buildURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ function encode(val) {
* @param {object} [params] The params to be appended
* @returns {string} The formatted url
*/
export default function buildURL(url, params) {
export default function buildURL(url, params,paramsSerializer) {
/*eslint no-param-reassign:0*/
if (!params) {
return url
}

var serializedParams
if (utils.isURLSearchParams(params)) {
if (paramsSerializer) {
serializedParams = paramsSerializer(params)
} else if (utils.isURLSearchParams(params)) {
serializedParams = params.toString()
} else {
var parts = []
Expand Down

0 comments on commit cae1043

Please sign in to comment.