const params = new URLSearchParams();//实现js参数转urlcode编码,直接可以传到url去请求
params.append('param1', 'value1');
params.append('param2', 'value2');
console.log(params.get('param1')) //获取到参数了
const urlObject = new URL(urlStr);// 先转为url对象,通过对象或者属性search可以获取到参数的字符
console.log(urlObject,"urlObject")
const param = new URLSearchParams(urlObject.search); //参数的字符转URLSearchParams实例对象,再通过api获取参数属性
// 遍历所有参数
for (const [key, value] of param.entries()) {
console.log(`${key}: ${value}`,"获取url参数");
}
标签:const,URLSearchParams,url,js,urlObject,参数,params
From: https://www.cnblogs.com/jocongmin/p/18227419