vue-reset-data
v1.1.6
Published
A mixin to allow reset the component data to some point on time for VueJS
Downloads
7
Readme
vue-reset-data
A mixin to reset your data to some point of time for VueJS components
Install
NPM:
npm i --save vue-reset-data
Usage instructions
Install the mixin globally
import Resetter from 'vue-reset-data';
Vue.use(Resetter);
Or import it as an individual mixin on your component
import {ResetterMixin} from 'vue-reset-data';
export default {
...
mixins: [ResetterMixin],
...
}
How to use it
- Call thefunction
initResetPlugin
to init the mixin at any point of the lifecycle of your component (Preferably on created or mounted):
export default {
created() {
this.initResetPlugin()
}
}
- When you want to reset some, call the function
resetData
:
export default {
methods: {
yourMethod() {
this.resetData([keys]);
}
}
}
- keys: Arrays of strings containing the names of the data key you want to reset or a simple string with the name of the key to reset. If this value is null, will reset the whole data.
This mixin include a method named $clone to clone in deep objects. Use as follow:
export default {
methods: {
yourMethod() {
const clonedObject = this.$clone(objectToClone);
}
}
}
NOTE: Do not use the key $originalData
as part of your data.
License
MIT