getUrlParams = (url) => {
// const searchPar = new URLSearchParams(url)
//'https://baidu.com/index?id=233&age=18&name=张三'
let arr=url.split("?"); //[ 'https://baidu.com/index', 'id=233&age=18&name=张三' ]
const paramsObj = {}
arr = arr[1].split('&') //[ 'id=233', 'age=18', 'name=张三' ]
for(let i = 0; i <arr.length; i++){
let brr = arr[i].split('=')
paramsObj[brr[0]] = brr[1]
}
return paramsObj
//{ id: '233', age: '18', name: '张三' }
}
解析url参数,参数转为对象格式
最新推荐文章于 2023-09-19 09:32:06 发布