vue-inherits

1.2.0 • Public • Published

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';
    },
  },
};

Package Sidebar

Install

npm i vue-inherits

Weekly Downloads

3

Version

1.2.0

License

ISC

Unpacked Size

4.85 kB

Total Files

6

Last publish

Collaborators

  • liyupku2000