获取地址栏的参数
方法一:
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; };
方法二:
GetRequest() { var url = window.location.href var theRequest = new Object() if (url.indexOf('?') != -1) { var str = url.split('?')[1] let strs = str.split('&') for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]) } } return theRequest }
created(){ this.GetRequest().name }