From 38dcff720d81922a4cec76383602f791eb867c48 Mon Sep 17 00:00:00 2001 From: hankaibo Date: Wed, 29 Dec 2021 22:46:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20#=20=E5=9C=A8=20=3F?= =?UTF-8?q?=20=E4=B9=8B=E5=89=8D=E6=97=B6=EF=BC=8Clocation.search=E5=8F=96?= =?UTF-8?q?=E5=80=BC=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/util.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/util.js b/src/utils/util.js index 7ec346d..7b436b1 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -7,8 +7,14 @@ export function getNowTime () { } export function getUrlParam (name) { - const search = window.location.search; - if (search !== '') { + let {search} = window.location; + const {hash} = window.location; + // # 在 ? 之前,即 http://localhost/#file?key=value,会导致 search 为空。 + if (search === '' && hash !== '') { + // 为 search 补上前缀'?',以便后面的逻辑处理不变。 + search = `?${hash.split('?')[1]}`; + } + if (search !== '' && search !== undefined) { const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); const r = search.substr(1).match(reg); if (r != null) { @@ -103,4 +109,4 @@ export const isMacOs = hasUaName('macintosh'); export const isOldEdge = hasUaName('edge') && !hasUaName('chrome'); -export const isIE = isOldEdge || hasUaName('trident') || hasUaName('msie'); \ No newline at end of file +export const isIE = isOldEdge || hasUaName('trident') || hasUaName('msie');