Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Mixins with same name function Vuejs

Tags:

mixins

vue.js

Hello I have this problem with vuejs and mixin. I have a component that has 2 Mixin:

 export default {
 ...
 mixins:[Mixin1, Mixin2],
 ..
}

Both Mixins have a function named "delete", so If in my component I have a method like:

methods:{
 deleteObj(){
    this.delete()
 }
}

I don't know which one function I call. I know the simplest way is call with a different name the functions but is there a way to specify wich mixin to use?

like image 259
LorenzoBerti Avatar asked Sep 19 '17 10:09

LorenzoBerti


1 Answers

If you duplicated definitions in methods in mixins, the last mixin will override the previous definitions. In your case this.delete() must called from Mixin2.

But if have lifecycle hooks like mounted, created ... those will be executed one by one in vuejs. There are some strategies followed for merging, vuejs itself you can found more at https://v2.vuejs.org/v2/guide/mixins.html

like image 172
Suresh Velusamy Avatar answered Oct 20 '22 00:10

Suresh Velusamy