Here is the code I am using for a select input in Vue Bootstrap:
<b-form-select v-model="selectedgroup" class="mb-3" @change="searchSubGroup()">
<option :value="null">Select a group</option>
<option v-for="group in groupItem" :value="group.id">
{{group.nome}}
</option>
</b-form-select>
Whenever the searchSubGroup()
method is triggered by the @change event, it passes the previous value of selectedgroup
. For example, if I first select an option with value = 1, the method will be called with selectedgroup
as null
, then if I select another option with value = 2, the method will be called with selectedgroup
as 1.
searchSubGroup(){
this.axios.get("http://chart.solutions/public/api/produto/subgroup/search/" + this.selectedgroup + "/").then(response => {
if (response.data.erro) {
//console.log("subgroup doesnt exist")
}else{
this.subGroupItem = response.data;
}
})
}