I am currently working with a Vue.js component that serves as a form with a single field for an email input. The default value of this field, "email", is provided to the component by the parent as a prop. Upon form submission, I need to trigger an event to update the parent with the new value of the email.
Here is an example of how this is set up:
<parent>
<child :email="email" />
</parent>
The issue I am facing is related to how my child component is structured:
{
props: ['email'],
data() {return {d_email: this.email}
}
The problem arises because the input field in my form is defined like this:
<input type="text" v-model="d_email" :value="email" />
If I do not include the :value="email", the child component will not update when the email value changes in the parent, which is crucial. However, in order to send input changes back to the parent on form submission, I need to store the input value somewhere, which is where d_email comes into play.
The challenge is that when the child component is initially rendered, the prop email is null, causing d_email to be initialized as null as well. As a result, the input field always displays null.
What would be the best approach to tackle this situation?