mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-02-02 18:28:40 +08:00
Support array parameter parsing (#4300)
This commit is contained in:
parent
617e594d8d
commit
6d2de002ef
@ -20,14 +20,19 @@ export function getPopupContainer(node?: HTMLElement): HTMLElement {
|
||||
* @param obj
|
||||
* @returns {string}
|
||||
* eg:
|
||||
* let obj = {a: '3', b: '4'}
|
||||
* let obj = {a: '3', b: '4', c: ['1','2']}
|
||||
* setObjToUrlParams('www.baidu.com', obj)
|
||||
* ==>www.baidu.com?a=3&b=4
|
||||
* ==>www.baidu.com?a=3&b=4&c=1,2
|
||||
*/
|
||||
export function setObjToUrlParams(baseUrl: string, obj: any): string {
|
||||
let parameters = '';
|
||||
for (const key in obj) {
|
||||
parameters += key + '=' + encodeURIComponent(obj[key]) + '&';
|
||||
const value = obj[key];
|
||||
if (Array.isArray(value)) {
|
||||
parameters += `${key}=${encodeURIComponent(value.join(','))}&`;
|
||||
} else {
|
||||
parameters += `${key}=${encodeURIComponent(value)}&`;
|
||||
}
|
||||
}
|
||||
parameters = parameters.replace(/&$/, '');
|
||||
return /\?$/.test(baseUrl) ? baseUrl + parameters : baseUrl.replace(/\/?$/, '?') + parameters;
|
||||
|
Loading…
Reference in New Issue
Block a user