Last active
February 18, 2017 22:01
-
-
Save barnabas-szekeres/391be5ca90fc145019c6 to your computer and use it in GitHub Desktop.
Store states in sessionstorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Component | |
| import Counter from '../store/counter'; | |
| export default { | |
| data() { | |
| return { | |
| }; | |
| }, | |
| computed: { | |
| counter() { | |
| return Counter.state; | |
| } | |
| }, | |
| watch: { | |
| itinerary: { | |
| handler() { | |
| sessionStorage.setItem('counter', JSON.stringify(this.$get('counter'))); | |
| }, | |
| deep: true | |
| } | |
| }, | |
| ready() {}, | |
| methods: {}, | |
| replace: true, | |
| template: require('./template.html'), | |
| components: { | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Store | |
| let session = JSON.parse(sessionStorage.getItem('counter')); | |
| let model = { | |
| count: 1 | |
| }; | |
| export default new Vuex.Store({ | |
| state: Object.is(session, null) ? model : session | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment