获取地址栏参数转成对象

export const quertObject = (url) => {
  const queryString = url.split('?')[1]
  const obj = {}
  const arr = queryString.split('&')
  for (let i = 0; i < arr.length; i++) {
    const key = arr[i].split('=')[0]
    const value = arr[i].split('=')[1]
    obj[key] = value
  }
  return obj
}
export const getQueryParams = () => {
  const result = {}
  const querystring = window.location.search
  const reg = /[?&][^?&]+=[^?&]+/g
  const found = querystring.match(reg)
  if (found) {
    found.forEach((item) => {
      let temp = item.substring(1).split('=')
      let key = temp[0]
      let value = temp[1]
      result[key] = value
    })
  }
  return result
}
原文地址:https://www.cnblogs.com/wuqilang/p/15187538.html