How can I assign data from a prop to a form object?
Can anybody please tell me how to assign data to a form object in a component? I pass the data to the component via a prop and that is working, so I can display this data (which is just a string to keep it simple) in the component.
But in this component I have a form object and I cannot figure it out how to pass that string to the input field of the form. Here is the example:
The way it works is that you define your data on the parent component and give it a value, then you go to the child component that needs that data and pass the value to a prop attribute so the data becomes a property in the child component https://prepaidgiftbalance.net/
@sti3bas Thanx for the hint:
when i hardcode a title in the parent, I can use either your approach or I can use created() or mounted() and that all works.
So I have to figure out, that the child component is loaded after the axios call sent the data.
@anaxarchos yes, exactly. You can also use computed property in your child component, then it will create new form object automatically whenever props changes:
@sti3bas This displays the title in the input field, but as @mironmg mentioned, this does not work, because each time I hit the update button a new form is set up and the errors are gone with the wind.
@mironmg Thanx for the code, but this does not work. While the method getData() is waiting for the axios reply, the TitleForm component is already been populated with an empty title from data().
At least I did not get it to work.
And using v-text in the child component does display the correct title from the prop, but this is not populated in the form object.
Now I found a way around. I just pass the id as a prop to the child component. And there I do the axios call. Then I can apply the data to the form and emit it to the parent.