utils

180 阅读1分钟
  1. 获取url上的参数

     formatUrlParams() {
       let url = window.location.hash
       let obj = {}
       if (url.indexOf('?') !== -1) {
         let startIndex = url.indexOf('?') + 1
         let str = url.substr(startIndex)
         let strs = str.split('&')
         for (let i = 0; i < strs.length; i++) {
           obj[strs[i].split('=')[0]] = decodeURIComponent(strs[i].split('=')[1])
         }
         return obj
       }
     },
    

eg: formatUrlParams().paramName