Persist data in localStorage or anywhere for Vue.js apps
yarn add vue-persist
import VuePersist from 'vue-persist'
Vue.use(VuePersist)
new Vue({
template: '<input v-model="name" />',
data: { name: '' },
created() {
this.$persist(['name'])
}
})
Then the data of name
will be stored at localStorage and kept in sync.
Check out the demo, just type some words and refresh the page.
Type: string
Default: persist:store
The name of the localStorage store.
Type: number
Default: 0
Expire store in a specific amount of time (in millisecond), default to never expire.
Type: function
Default: k => localStorage.get(k)
The function we use to get stored data.
Type: function
Default: (k, v) => localStorage.set(k, v)
The function we use to store data.
Type: function
Default: k => localStorage.removeItem(k)
The function we use to clear data in store.
Type: Array
Required: true
Array of keys of state you want to keep in sync with localStorage.
Type: string
Default: options.name
Type: number
Default: options.expiration
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
vue-persist © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).
egoistian.com · GitHub @egoist · Twitter @rem_rin_rin