I have an json object returned from an API call like this:
"countries": [
{
"id": 1,
"iso": US,
"name": "United States",
},
{
"id": 2,
"iso": FR,
"name": "France",
},
{
"id": 3,
"iso": GB,
"name": "United Kingdom",
},
]
In my vue component:
<select v-model="country">
<option v-for="country in countries" :value="country.id">{{ country.name }}</option>
</select>
How can I have pre-selected the third json instance based on the iso code?
The following code inside v-for does not work
:selected="country.iso === 'GB'"
I could do of course
data: function () {
country: 3
}
but I want to declare the default selected value based on iso code, not id.
I do not want to change iso as the model's value, as I am going to send it as post request to my API. If I did this, I could parse the whole json object to find the id from its iso code, but I am not sure this would be the cleanest solution.
Thanks