diff --git a/src/utils.ts b/src/utils.ts index 9485918..1542584 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -128,7 +128,17 @@ const utils = { */ getQueryParameters(search: string) { const searchParams = new URLSearchParams(search); - return Object.fromEntries(searchParams.entries()); + const paramValue = Object.fromEntries(searchParams.entries()); + for (const key in paramValue) { + if (paramValue[key] === 'null') { + (paramValue[key] as any) = null; + } + if (paramValue[key] === 'undefined') { + (paramValue[key] as any) = undefined; + } + } + + return paramValue; }, /** * 获取图片的Base64格式 diff --git a/test/utils.test.ts b/test/utils.test.ts index 798a63f..79bdc46 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -323,8 +323,8 @@ describe('utils:', () => { expect(getQueryParameters('?a=1&b=2')).toEqual({ a: '1', b: '2' }); expect(getQueryParameters('?a=1&b=undefined')).toEqual({ a: '1', - b: 'undefined', + b: undefined, }); - expect(getQueryParameters('?a=1&b=null')).toEqual({ a: '1', b: 'null' }); + expect(getQueryParameters('?a=1&b=null')).toEqual({ a: '1', b: null }); }); });