DEV Community

Discussion on: Call super method in Vue Component

Collapse
 
anduser96 profile image
Andrei Gatej

Thank you for sharing! I didn't know about that library, but in such cases I'd use the $parent property.

Example:

// myMixin.js
export default {
    methods: {
        sayHello () {
            console.log(this.message)
        }
    }
}
// Parent component
import myMixin from './path';
import Child from './ChildPath';

export default {
  mixins: [myMixin],
  components: { Child }
  data: () => ({
    message: 'hello from parent component!'
  })
}
// Child Component
export default {
  created () {
    this.$parent.sayHello();
    console.log('hello from child component!')
    /*
    hello from parent component!
    hello from child component!
    */
  }
}

Collapse
 
ashraful profile image
Mohamad Ashraful Islam

suppose you extended more than one mixin. And all the mixin have same method name. Is $parent will work?

Collapse
 
rhymes profile image
rhymes

No you can't, but if you control the mixins, isn't it easier to change the name of the methods?

Thread Thread
 
ashraful profile image
Mohamad Ashraful Islam

yeah, that's good I know. Thanks

Collapse
 
revel109 profile image
Abu Yusuf

Cool, Thanks for sharing. I was looking for something you did share here.

Collapse
 
ashraful profile image
Mohamad Ashraful Islam

Btw, it was written by me :p

Thread Thread
 
revel109 profile image
Abu Yusuf

Yes. I know that :D