将url上携带的参数转化成js对象

 getRequestParams() {
    const url = window.location.search; // 获取url中"?"符后的字串
    const theRequest = {};
    if (url.indexOf('?') !== -1) {
      const str = url.substr(1);
      const strs = str.split('&');
      for (let i = 0; i < strs.length; i++) {
        theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
      }
    }
    return theRequest;
  },

 

posted @ 2021-08-18 18:07  吃好每一口饭  阅读(171)  评论(0)    收藏  举报