URL相关工具方法
pnpm add @shencom/utils
# or
pnpm add @shencom/utils-url
import { UrlParamsToObject } from '@shencom/utils';
// import { UrlParamsToObject } from '@shencom/utils-url';
UrlParamsToObject
- 说明: url 参数转对象
- 类型:
(url?: string) => Record<string, string>
- 参数:
-
url
- 链接地址(默认: 当前地址)
-
- 示例:
// https://example.com UrlParamsToObject(); // {} // https://example.com?name=John&age=30 UrlParamsToObject(); // {'name': 'John', 'age': '30'} // https://example.com/index.html?scid=123&aa=true#/detail?id=1 UrlParamsToObject(); // {'scid': '123', 'aa': 'true'}
UrlParam
- 说明: 获取 url 参数中指定的key
- 类型:
(key: string) => string | undefined
- 参数:
-
key
- 参数key
-
- 示例:
// https://example.com UrlParam(''); // undefined UrlParam('abc'); // undefined // https://example.com?name=John&age=30 UrlParam('name'); // 'John' UrlParam('age'); // '30' // https://example.com/index.html?scid=123&aa=true#/detail?id=1 UrlParam('scid'); // '123' UrlParam('aa'); // 'true'