1👍
If you read more about slot scope here,
That slot has access to the same instance properties (i.e. the same “scope”) as the rest of the template.
Since, you are passing your form
via slot
, you would already be having the access to the parent
component instance.
Also, as mentioned in the docs, its good to remember
Everything in the parent template is compiled in parent scope; everything in the child template is compiled in the child scope.
So, when you write your component,
<template>
<ModalComponent>
<form @submit="toggleModalVisibility">
...
</form>
</ModalComponent>
</template>
any method passed to form
will have access to state
of the parent component.
Now, if you can just set a data property to toggle the visibity of the modal component in the parent and a method to toggle this property
data: () => {
return {
showModal: false //or true
}
},
methods: {
toggleModalVisibility() {
this.showModal = !this.showModal;
}
}
You can just assign this method to onSubmit handler of the form
form @submit="toggleModalVisibility"
0👍
If you want the parent to close the dialog, then you should (probably) also make the parent responsible for opening the dialog. Otherwise, you can end up with components fighting each other for control.
That’s easy enough to do. Have the parent pass a property to your custom component that enables or disables the dialog. Since the parent is also providing the form as a slot, the parent can handle events from that form and set the property correctly.