Sometimes, we want to use local storage with Vue.js.
In this article, we’ll look at how to use local storage with Vue.js.
How to use local storage with Vue.js?
To use local storage with Vue.js, we can use the localStorage.getItem and localStorage.setItem methods.
For instance, we write
localStorage.getItem('YourItem')
in our component code to return the local storage entry with the 'YourItem' key.
And we write
localStorage.setItem('YourItem', response.data)
to call localStorage.setItem to save a local storage entry with key 'YourItem' and response.data as the entry’s value.
Conclusion
To use local storage with Vue.js, we can use the localStorage.getItem and localStorage.setItem methods.