【JavaScript】获取url中的参数方法封装

    getParams() {
      const url = window.location.href
      const index = url.indexOf('?') + 1
      const params = url.substr(index)
      const arr = params.split('&')
      const o = {}
	  
      for (var i = 0; i < arr.length; i++) {
        var tmpArr = arr[i].split('=')
        var key = tmpArr[0]
        var value = tmpArr[1]
        o[key] = value
      }
		
      return o
    }
posted @ 2021-11-17 09:44  努力挣钱的小鑫  阅读(85)  评论(0编辑  收藏  举报