Skip to content

ajomuch92/vue-reset-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. 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()
  }
}
  1. 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

About

A mixin to reset your data to some point on time for VueJS component

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published