获取url参数

简单的记录一下以免忘记~


export function getUrlParams() {
  const url = window.location.href; // 获取url中"?"符后的字串
  const theRequest: T = {} as T;
  if (url.indexOf('?') !== -1) {
    const str = url.split('?')[1];
    const strs = str.split('&');
    for (let i = 0; i < strs.length; i++) {
      theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
    }
  }
  return theRequest;
}


你可能感兴趣的:(获取url参数)