Created
May 17, 2024 07:13
-
-
Save andrejsharapov/d9619bdba9edc3b2d15665acb205b150 to your computer and use it in GitHub Desktop.
Save states to localStorage (for Vue 2)
This file contains 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
// change `nameState` | |
export default { | |
data: () => ({ | |
nameState: 0, | |
}), | |
watch: { | |
nameState(state) { | |
localStorage.setItem('nameState', JSON.stringify(state)); | |
}, | |
}, | |
mounted() { | |
if (localStorage.nameState) { | |
this.nameState = JSON.parse(localStorage.getItem('nameState')); | |
} | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment