searchQuery (key) {
let str = window.location.search
let pattern = new RegExp(’((\w+)=([^&?]*))’, ‘gi’)
let results = str.match(pattern)
let params = {}
if (results) {
for (let i = 0, len = results.length; i < len; i++) {
let s = results[i].split(’=’)
params[decodeURIComponent(s[0])] = decodeURIComponent(s[1])
}
}
return key ? params[key] : params
}
分享一个检索url参数并转为对象的共用函数
最新推荐文章于 2024-04-22 04:04:09 发布