let url = window.location.href let fun = getUrlParams(url) if (fun.token) { setToken(fun.token); if (url) { const paramsStr = url.split('?')[1] localStorage.setItem('userName', paramsStr.split("=")[1]) } } function getUrlParams(url) { const arrSearch = url.split('?').pop().split('#').shift().split('&'); let obj = {}; arrSearch.forEach((item) => { const [k, v] = item.split('='); obj[k] = v; return obj; }); return obj; };
标签:obj,url,获取,参数,split,fun,const,let,地址栏 From: https://www.cnblogs.com/yjd-05/p/17479655.html