当前位置:网站首页>sessionStorage值改变后,页面利用window.sessionStorage.getItem()获取到的值不会更新
sessionStorage值改变后,页面利用window.sessionStorage.getItem()获取到的值不会更新
2022-08-09 00:01:00 【juvialoxer】
解决办法:
一,在需要id的页面利用created定时获取window.sessionStorage.getItem(“id”)
private created() {
setInterval(() => {
this.id= window.sessionStorage.getItem("id");
}, 1000);
}
当然,这种方法是耗性能的,不得已不建议使用
二,将需要的id存在vuex中
@Watch("$store.state.auth.id", {
deep: true, immediate: true })
private getAgentInfo(newVal: any, oldVal: any) {
console.log(newVal);
console.log(oldVal);
}









