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