I am building a website with NUXT.
I have setup the page components in the Pages folder. I'd like to have a BasePage component, and then extend this base component for new pages that would inherit common methods that are within the base component.
I am trying to use mixins but it's not working
For example I have:
Children:
- page a
- page b
Parent:
- page-mixins
The mixin (or parent) has a method, initPage().
I want to also have the same method, initPage(), in the children. When I call initPage() from a child page, I need this method to run from parent and child. The order is parent then child.
Basically I am trying to do in NUXT what you would typically do in an OOP language where you inherit a base class then call super.initPage() from within the child class method.
I am trying to use optionMergeStrategies.methods but with no luck. Please help.
Thanks
UPDATE:
I am sure it is possible to make this work using a custom merge strategy (using optionMergeStrategies option). I tried but don't get how it works. So I needed another solution. Well, all I did is, in the mixin (or parent) I made the method name _initPage() (notice the underscore), while in the page components (the children) I kept the name initPage (without underscore). Now all I need to do is, from a child component, and from within the initPage() method, I just call the parent method by using _initPage(). This behaves exactly like calling super.initPage(). This can be applied to as many methods as you need, just add an underscore within the mixin (or parent) methods, and call them from the child. I named the mixin file, pageMixins. This mixin has many inherited methods such as _initPage, _animateIn, _animateOut, _dispose, loadPage... etc.
Parent (mixins file):
_initPage: function() {
// code...
}
Child (page component)
initPage: function() {
this._initPage();
// code...
}