js 解析地址栏参数

    getQueryParams() {
      const paramsString = new URLSearchParams(window.location.search).toString(); // 将查询字符串转换为字符串
      const paramsArray = paramsString.split('&'); // 将字符串按 & 分割成数组

      // 遍历数组,将每个参数存储到对象中
      const paramsObj = {};
      for (let i = 0; i < paramsArray.length; i++) {
        const [key, value] = paramsArray[i].split('=');
        paramsObj[decodeURIComponent(key)] = decodeURIComponent(value);
      }

      return paramsObj
    },
posted @ 2023-05-16 11:56  DL·Coder  阅读(116)  评论(0编辑  收藏  举报