<div>
<b-form-select v-model="selected" :options="options"></b-form-select>
<b-form-select v-model="selected" :options="options" size="sm" class="mt-3"></b-form-select>
<div class="mt-3">Selected: <strong>{{ selected }}</strong></div>
</div>
export default {
data() {
return {
selected: null,
options: [
{ value: null, text: 'Please select an option' },
{ value: 'a', text: 'This is First option' },
{ value: 'b', text: 'Selected Option' },
{ value: { C: '3PO' }, text: 'This is an option with object value' },
{ value: 'd', text: 'This one is disabled', disabled: true }
]
}
}
}
Generate your select options by passing an array or object to the options
props:
Selected:
Selected:
<div>
<b-form-select v-model="selected" class="mb-3">
<option :value="null">Please select an option</option>
<option value="a">Option A</option>
<option value="b" disabled>Option B (disabled)</option>
<optgroup label="Grouped Options">
<option :value="{ C: '3PO' }">Option with object value</option>
<option :value="{ R: '2D2' }">Another option with object value</option>
</optgroup>
</b-form-select>
<div class="mt-2">Selected: <strong>{{ selected }}</strong></div>
</div>
export default {
data() {
return {
selected: null
}
}
}
<div>
<b-form-select
v-model="selected"
:options="options"
class="mb-3"
value-field="item"
text-field="name"
disabled-field="notEnabled"
></b-form-select>
<div class="mt-3">Selected: <strong>{{ selected }}</strong></div>
</div>
export default {
data() {
return {
selected: 'A',
options: [
{ item: 'A', name: 'Option A' },
{ item: 'B', name: 'Option B' },
{ item: 'D', name: 'Option C', notEnabled: true },
{ item: { d: 1 }, name: 'Option D' },
]
}
}
}
If you want to customize the field property names (for example using name
field for display text
) you can easily change them by setting the text-field
, html-field
, value-field
, and disabled-field
props to a string that contains the property name you would like to use:
<div>
<b-form-select v-model="selected" :options="options"></b-form-select>
<div class="mt-3">Selected: <strong>{{ selected }}</strong></div>
</div>
export default {
data() {
return {
selected: null,
options: [
{ value: null, text: 'Please select some item' },
{ value: 'a', text: 'This is First option' },
{ value: 'b', text: 'Default Selected Option' },
{ value: 'c', text: 'This is another option' },
{ value: 'd', text: 'This one is disabled', disabled: true },
]
}
}
}
In non multiple
mode, <b-form-select>
returns the a single value
of the currently selected option.