123456789101112131415161718192021222324252627282930313233343536373839 |
- /*
- 解析URL参数
- url:要解析的地址
- fkey:要查找的参数
- let locationLocaturl = window.location.search;
- let openId = getUrlParams(locationLocaturl,"openId");
- */
- function getUrlParams(url, fkey) {
- if (decodeURIComponent(url).indexOf('?') > -1) {
- var result = [];
- var urlParamsArr = decodeURIComponent(url).split('?');
- urlParamsArr.shift();
- let newUrlParamsArr = urlParamsArr.join('&').split('&');
- for (var i = 0; i < newUrlParamsArr.length; i++) {
- var paramKey = newUrlParamsArr[i].split('=')[0];
- var paramValue = newUrlParamsArr[i].split('=')[1];
- result.push({
- key: paramKey,
- value: paramValue
- });
- }
- if (fkey) {
- let keyArr = result.find(function (result) {
- return result.key === fkey;
- });
- if (!!keyArr) {
- let fkeyValue = keyArr.value;
- return fkeyValue;
- } else {
- return false;
- }
- } else {
- return result;
- }
- }
- }
- export default getUrlParams;
|