vue-reset-data

1.1.6 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i vue-reset-data

Weekly Downloads

1

Version

1.1.6

License

MIT

Unpacked Size

5.28 kB

Total Files

5

Last publish

Collaborators

  • ajomuch92