urlSearchParams.set(name, value)
将与 name 关联的 URLSearchParams 对象中的值设置为 value。如果存在任何预先存在的名称为 name 的键值对,则将第一个此类键值对的值设置为 value,并删除其他所有键值对。如果不存在,则将该名称-值对附加到查询字符串中。
【Sets the value in the URLSearchParams object associated with name to
value. If there are any pre-existing name-value pairs whose names are name,
set the first such pair's value to value and remove all others. If not,
append the name-value pair to the query string.】
const params = new URLSearchParams();
params.append('foo', 'bar');
params.append('foo', 'baz');
params.append('abc', 'def');
console.log(params.toString());
// Prints foo=bar&foo=baz&abc=def
params.set('foo', 'def');
params.set('xyz', 'opq');
console.log(params.toString());
// Prints foo=def&abc=def&xyz=opq