Skip to content
Advertisement

Link v-model to a object’s property in Vue.js 2

I use Vue.js 2 and I have this array, obtained from this API call (https://developers.themoviedb.org/3/genres/get-movie-list this one) that I’ve used to make a select in HTML:

JavaScript

What I want is to link the v-model, which is declared in Js as an empty string, to the property id of this array. I can’t extract the property and use an array with only it, because options’ name is a v-for that prints genres.name At the point I am now when I do the console.log on the v-model it returns an empty string, means that v-model doesn’t take any value. The select is this:

JavaScript

In data the v-model variable is declared this way:

JavaScript

I check the v-model status here in this function

JavaScript

Advertisement

Answer

Do you mean that this array is a list of elements to be options in a select? If yes, you need to bind every option value (previously generated in a loop by v-for) with the element id:

JavaScript
Advertisement