话不多说,进入正题:
一:获取路由拼接参数如下代码:
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
}
var code = getQueryString('aa'); //例如:http://localhost:8083/blank.html?aa=CNimsJb%2BHzIwsR4VMdkHdjnXE7m
二:常用的存储代码
window.commonObj.postAjax(window.api.DecodeText + "?code=" + code).done(function (res) {
if (res.code == 0) {
var data = res.result;
//存储
window.localStorage.setItem("paperLoginOpen", data.phone); //存储单个字段
window.localStorage.setItem("paperLoginData", JSON.stringify(data));//存储json
//如果是ajax
//可以这样做,就不需要没次都写入一次,只需要把ajax根据get和post封装成公共的方法写入一次就够了
ajax({
url: url,
method: "GET",
headers: { Authorization: window.localStorage.getItem("paperSessionId") }
})
//获取
var paperLoginOpen= window.localStorage.getItem("paperLoginOpen");
var paperLoginData = JSON.parse(window.localStorage.getItem("paperLoginUser"))
}