Skip to content

Instantly share code, notes, and snippets.

@ciming
Created September 1, 2022 06:00
Show Gist options
  • Save ciming/4cc3e543a7b512c32a58718fb6dafb25 to your computer and use it in GitHub Desktop.
Save ciming/4cc3e543a7b512c32a58718fb6dafb25 to your computer and use it in GitHub Desktop.
//生成URL
const searchParams = new URLSearchParams();
searchParams.set('foo', 'bar');
searchParams.set('hello', 'world');
const searchParams = new URLSearchParams([
['foo', 'bar'],
['hello', 'world'],
]);
const searchParams = new URLSearchParams({
foo: 'bar',
hello: 'world',
});
const searchParams = new URLSearchParams('foo=bar&hello=world');
// Logs 'foo=bar&hello=world'
console.log(searchParams.toString());
//URL解析
Object.fromEntries(searchParams);
const searchParams = new URLSearchParams(location.search);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment