Skip to content

Instantly share code, notes, and snippets.

@shuiRong
Created May 25, 2021 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuiRong/91df52db8d41e80b6ab211f9f46688ae to your computer and use it in GitHub Desktop.
Save shuiRong/91df52db8d41e80b6ab211f9f46688ae to your computer and use it in GitHub Desktop.
parseParam 解析url参数,hash模式,考虑到前后两种参数可能
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