PHP
·
发表于 5年以前
·
阅读量:8283
//将对象序列化成url参数传递
function stringifyUrl(search = {}) {
return Object.entries(search).reduce(
(t, v) => `${t}${v[0]}=${encodeURIComponent(v[1])}&`,
Object.keys(search).length ? "?" : ""
).replace(/&$/, "");
}
console.log(stringifyUrl({
age: 27,
name: "YZW"
})); // "?age=27&name=YZW"