1.2.0 • Published 5 years ago

vue-inherits v1.2.0

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

vue-inherits

Version

This vue plugin chains the methods properties of parent and child with __proto__. Hense, the following example will not throw exception even if the Mom object does not have makeMsg method.

Example:

const Grandma = {
  data() {
    return { msg: '' };
  },
  beforeMount() {
    this.makeMsg();
  },
  methods: {
    makeMsg() {
      this.msg += ' Grandma';
    },
  },
};

const Mom = {
  extends: Grandma,
};

const Daughter = {
  extends: Mom,
  methods: {
    makeMsg() {
      Mom.methods.makeMsg.call(this);
      this.msg += ' Daughter';
    },
  },
};

You can also apply inheritance on mixins.

const GrandpaMixin = {
  methods: {
    mixinMakeMsg() {
      this.msg += ' GrandpaMixin';
    },
  },
};

const DadMixin = {
  extends: GrandpaMixin,
};

export {
  extends: DadMixin,
  methods: {
    mixinMakeMsg() {
      DadMixin.methods.mixinMakeMsg.call(this);
      this.msg += ' SonMixin';
    },
  },
};