I'm a beginner with Vue.js
and Vuetify.js
, and I am encountering some difficulties with the following:
<v-select v-model="car.type"
:items="types"
label="Type"
></v-select>
<div v-if="car.type === 'fiat'">
<v-text-field v-model="car.km" label="KM"></v-text-field>
<v-text-field v-model="car.color" label="Color"></v-text-field>
</div>
<div v-else-if="car.type === 'bmw'">
<v-text-field v-model="car.color.first" label="First color"></v-text-field>
<v-text-field v-model="car.color.second" label="Second color"></v-text-field>
</div>
While it somewhat works and changes the input fields based on the type
, an error is appearing:
[Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating '_vm.car.color.first')"
If I change the v-model
to car.colorfirst
, without the nested JSON
object, it works. This could be because car.color.first
is not defined yet.
However, I need the other method to work.
Any suggestions on what to do? Does this make sense?
Check out the live demo here: https://codepen.io/alfredballe84/pen/MBXwKx