I have a vue component that is performing a series of conditionals to check if there is previous data when editing a form. Since the form is being edited there is always previous data but if I type something into the input field and click the save button, my newly typed input is not being persisted but rather the same old data is remaining. I understand that it is happening because the v-if condition is always true but I cannot think of a way to modify the condition if the user types new data in to replace it. The original job is being passed in as a prop which contains the old/original data.
A conditional from my vue:
<div v-if="job.title">
<input :value="job.title" id="title" name="title" type="text" required>
</div>
<div v-else>
<input v-model="newJob.title" id="title" name="title" type="text" required>
</div>
props: {
route: String,
job: Object,
},
data() {
return {
newJob: {
title: ''
},
}
},
So when I type new information the v-model for the newJob is not being updated in the vue dev tools. How do I get the newJob field to update IF the user types something in, otherwise continue to save the old/original value that was in the edit form when the page loaded.
job.titleexists then the first input is shown and you are not usingv-modelor@inputto handle changes, so nothing will change, right?