This package provides a SaveState
mixin that automatically saves any change in the state of your component to localStorage. The next time that component gets initialized it will restore its state from the saved values in local storage.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
The best postcards will get published on the open source page on our website.
You can install the package via yarn:
$ yarn add vue-save-state
or npm
$ npm install vue-save-state
In order to save the state of your component you'll need to add the SaveState
mixin:
import saveState from 'vue-save-state';
export default {
mixins: [saveState],
...
}
Next you'll need to add a method called getSaveStateConfig
:
import saveState from 'vue-save-state';
export default {
mixins: [saveState],
// ...
methods: {
getSaveStateConfig() {
return {
'cacheKey': 'nameOfYourComponent',
};
},
},
}
With these steps done any change to the state of your component will get written to local storage. The value given in cacheKey
determines to which key in local storage the state of this component will get written. When the component is created it'll restore its state from local storage.
There's also a configuration option to determine which properties of the state should be saved/restored:
import saveState from 'vue-save-state';
export default {
// ...
methods: {
getSaveStateConfig() {
return {
'cacheKey': 'nameOfYourComponent',
'saveProperties': ['title', 'text'],
};
},
},
}
With this configuration only the title
and text
properties of your state will get saved/restored.
Please see CHANGELOG for more information what has changed recently.
$ npm run test
Please see CONTRIBUTING for details.
If you discover any security related issues, please contact Freek Van der Herten instead of using the issue tracker.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
The MIT License (MIT). Please see License File for more information.