解决vuex中store保存数据,刷新页面会清空得问题
生活随笔
收集整理的這篇文章主要介紹了
解决vuex中store保存数据,刷新页面会清空得问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.在App.vue下加入
mounted() {window.addEventListener("unload", this.saveState);},methods: {saveState() {sessionStorage.setItem("state", JSON.stringify(this.$store.state));}}2.在store下的index.js文件下修改
state:sessionStorage.getItem('state') ? JSON.parse(sessionStorage.getItem('state')): {},總結(jié)
以上是生活随笔為你收集整理的解决vuex中store保存数据,刷新页面会清空得问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Objective-C中的@proper
- 下一篇: pajek的net文件格式