1.sessionStorage–切换用户的时候数据会置空
详解:sessionStorage生命周期为当前窗口或标签页,一旦窗口或标签页被永久关闭了,那么所有通过sessionStorage存储的数据也就被清空了。
在mounted中挂载:
if(sessionStorage.getItem(‘数据对象’)){
this.触发的方法函数(JSON.parse(sessionStorage.getItem(‘数据对象’)));
this.展示数据的参数 = this.数据对象.取出数据的参数
}
在方法中进行存储:
sessionStorage.setItem(‘数据对象’,JSON.stringify(this.数据对象))
2.localStorage–切换用户的时候数据不会置空
详解:localStorage生命周期是永久,这意味着除非用户显示在浏览器提供的UI上清除localStorage信息,否则这些信息将永远存在。
在mounted中挂载:
if(localStorage.getItem(‘数据对象’)){
this.触发的方法函数(JSON.parse(localStorage.getItem(‘数据对象’)));
this.展示数据的参数 = this.数据对象.取出数据的参数
}
在方法中进行存储:
localStorage.setItem(‘数据对象’,JSON.stringify(this.数据对象))