//在页面刷新时将vuex里的信息保存到sessionStorage里
window.addEventListener("beforeunload",()=>{
sessionStorage.setItem("store",JSON.stringify(this.$store.state))
})
//在页面加载时读取sessionStorage里的状态信息
if (sessionStorage.getItem("store")) {
this.$store.replaceState(
Object.assign(
{},
this.$store.state,
JSON.parse(sessionStorage.getItem("store"))
)
);
}
var _beforeUnload_time = 0,
_gap_time = 0;
var is_fireFox = navigator.userAgent.indexOf("Firefox") > -1; //是否是火狐浏览器
window.addEventListener("unload", function() {
_gap_time = new Date().getTime() - _beforeUnload_time;
if (_gap_time <= 5) {
Cookies.set('token', '', {expires: 1})
fetch(baseURL + 'login_out');
} else {
sessionStorage.setItem("store", JSON.stringify(_this.$store.state));
}
});
window.onbeforeunload = function() {
_beforeUnload_time = new Date().getTime();
};