Reputation: 395
<span class="input-group-btn" style="min-width: 100px">
<select class="form-control" v-model="field.related_field">
<option value="null"></option>
<option v-for="f in fields" v-bind:value="f.id" v-if="f.id != ''" v-bind:selected="f.id == field.related_field ? true : false">{{ f.label }}</option>
</select>
</span>
This is my code in vue js. I am trying to set the option selected if the user submitted anything before when I am fetching from database. I tried to bind with the selected attribute. Can anyone help with this, please?
Upvotes: 2
Views: 421
Reputation: 82439
v-model
takes care of this for you. Just set the expression you are binding with v-model
to the value you want.
this.field.related_field = <value you want to default to>
Upvotes: 2