Created
January 9, 2018 06:18
-
-
Save yy-dev7/8d143a4a31bcbc49be44204135be3eeb to your computer and use it in GitHub Desktop.
获取URL参数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取URL参数 | |
* // http://jsfiddle.net/draft/?foo=foo&bar=bar | |
console.log(getUrlParams('foo')); // "foo" | |
console.log(getUrlParams()); // {foo: "foo", bar: "bar"} | |
*/ | |
function getUrlParams(name, uri) { | |
const params = {} | |
const search = uri || window.location.search | |
search.replace(/[?&]+([^=&]+)=([^&]*)/gi, (str, key, value) => { | |
params[key] = value | |
}) | |
return params[name] || params | |
} | |
export default getUrlParams |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment