mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-03 11:20:16 +01:00
改进 getSearch 函数实现 (#7089)
* 🎨 改进 `getSearch` 方法 兼容 key 为空字符串与 value 为空字符串的 URL search params * 🎨 改进 `getSearch` 方法 * 🎨 style
This commit is contained in:
parent
4f2bca7e05
commit
67743b50ba
4 changed files with 9 additions and 19 deletions
|
|
@ -14,20 +14,10 @@ export const getRandom = (min: number, max: number) => {
|
|||
return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值
|
||||
};
|
||||
|
||||
export const getSearch = (key: string, link = window.location.search) => {
|
||||
if (link.indexOf("?") === -1) {
|
||||
return "";
|
||||
}
|
||||
let value = "";
|
||||
const data = link.split("?")[1].split("&");
|
||||
data.find(item => {
|
||||
const keyValue = item.split("=");
|
||||
if (keyValue[0] === key) {
|
||||
value = keyValue[1];
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return value;
|
||||
export const getSearch: (key: string, link?: string) => string | null = (key: string, link = window.location.search) => {
|
||||
// REF https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams
|
||||
const urlSearchParams = new URLSearchParams(link);
|
||||
return urlSearchParams.get(key);
|
||||
};
|
||||
|
||||
export const isBrowser = () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue