js 获取 url 里面的参数
2020-12-20 09:35
标签:fun string ring port href div rgb object ons js 获取 url 里面的参数 标签:fun string ring port href div rgb object ons 原文地址:https://www.cnblogs.com/Sabo-dudu/p/14048851.html/**
* 获取 url 里面的参数
* @param {string} url
* @returns {Object}
*/
export function getQueryObject(url) {
url = url == null ? window.location.href : url
const search = url.substring(url.lastIndexOf(‘?‘) + 1)
const obj = {}
const reg = /([^?&=]+)=([^?&=]*)/g
search.replace(reg, (rs, $1, $2) => {
const name = decodeURIComponent($1)
let val = decodeURIComponent($2)
val = String(val)
obj[name] = val
return rs
})
return obj
}