Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

vue如何实时监听sessionStorage的变化?

image.png

这个 “下载合同” 我会根据sessionStorage.contractDetail是否存在来判断他是否显示隐藏

但是这个sessionStorage.contractDetail是根据接口来返回的,请求时间可能1-3秒,现在问题一开始看不到这个按钮,F5刷新后就看到这个按钮了
(因为刚开始在请求接口,所以检测不到sessionStorage.contractDetail存在,就一直false,刷新后检测sessionStorage.contractDetail存在为true所以显示)

大佬们,有好的解决方案嘛?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我猜 你是后续调接口进行set缓存,但是你的get是之前获取的;
解决:
设置一个变量
初始化时 this.temp = sessionStorage.get()
接口返回正常set;
这时再赋值给this.temp;

或者:直接用vuex来处理;不用那么麻烦;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...