1.1.6 • Published 4 years ago
vue-reset-data v1.1.6
vue-reset-data
A mixin to reset your data to some point of time for VueJS components
Install
NPM:
npm i --save vue-reset-dataUsage 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
initResetPluginto 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