mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-04-26 03:07:56 +08:00
fix: 把 Yi.Vben5.Vue3 下的 packages 目录放出来
This commit is contained in:
24
Yi.Vben5.Vue3/packages/utils/src/helpers/request.ts
Normal file
24
Yi.Vben5.Vue3/packages/utils/src/helpers/request.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 一些发送请求 需要用到的工具
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add the object as a parameter to the URL
|
||||
* @param baseUrl url
|
||||
* @param obj
|
||||
* @returns {string}
|
||||
* eg:
|
||||
* let obj = {a: '3', b: '4'}
|
||||
* setObjToUrlParams('www.baidu.com', obj)
|
||||
* ==>www.baidu.com?a=3&b=4
|
||||
*/
|
||||
export function setObjToUrlParams(baseUrl: string, obj: any): string {
|
||||
let parameters = '';
|
||||
for (const key in obj) {
|
||||
parameters += `${key}=${encodeURIComponent(obj[key])}&`;
|
||||
}
|
||||
parameters = parameters.replace(/&$/, '');
|
||||
return /\?$/.test(baseUrl)
|
||||
? baseUrl + parameters
|
||||
: baseUrl.replace(/\/?$/, '?') + parameters;
|
||||
}
|
||||
Reference in New Issue
Block a user