function params(obj) {
let result = ''
for (let item in obj) {
if (obj[item]) {
result += `&${item}=${obj[item]}`
}
}
if (result) {
result = result.slice(1)
}
return result
}
const obj = {
name: '哈哈',
age: '18',
msg: ''
}
const url = `/get/info?${this.params(obj)}` // 输出 /get/info?name=哈哈&age=18
请求参数拼接
于 2021-03-15 16:59:47 首次发布