function params(obj) {
let result = '';
let item;
for (item in obj) {
if (obj[item] && String(obj[item])) {
result += `&${item}=${obj[item]}`;
}
}
if (result) {
result = '?' + result.slice(1);
}
return result;
}
const obj = {
name: '测试',
age: '24',
msg: ''
}
const url = `/get/info/${this.params(obj)}`;
console.log(url); // > /get/info/?name=测试&age=24
js将对象修改成get请求拼接的参数
最新推荐文章于 2024-01-29 15:23:44 发布