If I have data like so in Vue JS 2:
data : {
newBus: {
name: '',
hours: {
sunday: '',
}
}
}
And I set it here:
<input v-model="newBus.hours.sunday" type="text" placeholder="Sunday">
Adding a business this way works, the issue comes when I try to update them. The user clicks on the item from a list and then the saved data fills in the form like so:
<div v-for="bus in businesses" v-on:click="editBus(bus)" class="list-group-item bus-list-item">{{bus.name}}</div>
Method:
editBus: function (bus) {
/*Set post values to form*/
this.newBus = bus
},
But I get the error:
vue.js:1453 TypeError: Cannot read property 'sunday' of undefined
This happens immediately when the item to be updated is clicked. Any ideas?
EDIT: It appears to be related to the hours property not being avaliable on bus. If I console.log(bus) it doesn't show. But I need to add this data to this business. Is there a way to have it ignore data it doesn't yet have? What I don't understand is that if it was not nested...aka sunday: '' instead of hours: { sunday: ''} it works fine.
EDIT: Here is the CodePen recreation.