Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js close modal from child component

I want to close vuejs modal from child component inside this modal. Case:

<modal name="some-modal">
        <some-component></some-component>
</modal>

Inside SomeComponent i want to close some-modal. Is it good approach ? Can it be done better way ? Please adivse, Regards

like image 783
Juri Bojka Avatar asked Sep 11 '17 10:09

Juri Bojka


Video Answer


1 Answers

You need to emit an event from the child component using this.$emit('exit', true).

Then listen for that event in the parent component (Modal).

<modal name="some-modal">
    <some-component @exit="closeModal"></some-component>
</modal>

Then write the logic to closeModal function.

like image 119
Shubham Patel Avatar answered Nov 15 '22 07:11

Shubham Patel