new Vue({
el: '#app',
computed: {
selectedBoxes() {
return this.boxes.filter(box => box.checked).map(box => box.value);
}
},
data() {
return {
boxes: [
{ value: 1, text: 'Value 1', checked: false },
{ value: 2, text: 'Value 2', checked: false },
{ value: 3, text: 'Value 3', checked: false },
{ value: 4, text: 'Value 4', checked: false },
{ value: 5, text: 'Value 5', checked: false },
{ value: 6, text: 'Value 6', checked: false }
]
}
}
})
body { padding: 1rem; }
<link href="https://unpkg.com/bootstrap@4.3.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/bootstrap-vue@2.1.0/dist/bootstrap-vue.css" rel="stylesheet"/>
<script src="https://unpkg.com/vue@2.6.10/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.1.0/dist/bootstrap-vue.js"></script>
<div id="app">
<div class="font-weight-bold">
Using span and br
</div>
<span v-for="(box, index) in boxes">
<b-checkbox :key="index" v-model="box.checked" class="d-inline">
{{ box.text }}
</b-checkbox>
<!-- Render a <br> every 2nd checkbox -->
<br v-if="index % 2" />
</span>
<!--
Another option is to use the bootstrap grid system.
However this will create spacing between the elements based on the width of the row
-->
<div class="font-weight-bold mt-5">
Using row/cols
</div>
<b-row>
<b-col v-for="(box, index) in boxes" cols="6">
<b-checkbox :key="index" v-model="box.checked">
{{ box.text }}
</b-checkbox>
</b-col>
</b-row>
Selected boxes: {{ selectedBoxes.length > 0 ? selectedBoxes : 'Nothing selected' }}
</div>