/** * @author mi * @date 2019/3/5 * @project zhinengshuati */ // 获取url中search参数let getSearch = function (url) { let matched = /^(?:https?:\/\/[^?]*\?)(.*)/gi.exec(url) return matched ? matched[1] : '' }// 递归函数,循环匹配searchlet searchFn = function (search, query) { if (search) { let matched = /(\w+)=(\w*)/g.exec(search) if (matched) { query[matched[1]] = decodeURIComponent(matched[2]) searchFn(search.slice(matched.index + matched[0].length), query) } }}let parseUrl = function (url) { let query = {} searchFn(getSearch(url), query) return query}let url = 'http://localhost:3009/h5/test?recordID=161851&order=2'console.log(parseUrl(url)) // => { recordID: '161851', order: '2' }复制代码