I have a parent component and a child component. The child component is inside a dialog in the parent component. And this dialog is shown or hidden.
my parent component
<template>
<div>
<v-dialog v-model="dialog">
<product-form></product-form>
</v-dialog>
</div>
</template>
my child component (product-form)
<template>
<div>
.....
<input type="text" v-model="data">
.....
</div>
</template>
<script>
export default {
data: () => ({
data: '',
}),
methods:{
onSubmitProduct(){
//send data to server
}
},
}
</script>
I need to clear the child form whenever the dialog is shown. The problem is that I display the dialog through the parent component. NOTE: I do not want to use v-model in the child component because I need to send the data to the server from the child component and not the parent component.
Can someone help me?
* **SOLUTION ***
I was able to solve the problem using ref. I don't know if my solution is contrary to good practices. But it was the best I could.
//parent component
<template>
<div>
<v-dialog v-model="dialog">
<product-form ref="childComponent"></product-form>
</v-dialog>
</div>
</template>
this.$refs.childComponent.resetForm();
-
//child compopnent
<template>
<div>
.....
<input type="text" v-model="data">
.....
</div>
</template>
<script>
export default {
data: () => ({
data: '',
}),
methods:{
onSubmitProduct(){
//send data to server
},
resetForm(){
//code to reset form
}
},
}
</script>