-
-
Save shuiRong/91df52db8d41e80b6ab211f9f46688ae to your computer and use it in GitHub Desktop.
parseParam 解析url参数,hash模式,考虑到前后两种参数可能
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
getUrlAllParam(...args) { | |
// 获取url参数的值,在hash路由的情况下,同时。适配参数在#前,和在#后的情况。 | |
if (args.length === 0) return undefined | |
const url = decodeURIComponent(window.location.href) | |
const reg = | |
args.length === 1 | |
? new RegExp(`[&?]${args[0]}=([^&%#]+)`) | |
: new RegExp(`[&?](?:${args.join('|')})=([^&%#]+)`) | |
const matchArray = url.match(reg) | |
return matchArray === null ? undefined : matchArray[1] | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment