Search code examples
vue.jsbootstrap-4vue-directives

Vue v-model data binding issue


I have a pair of standard Bootstrap radio buttons and I wanted v-model to set a value in the vue data object when one is selected.

This works just fine in a JSfiddle, however this doesn't work when running locally on my own environment.

I can get other directives working fine like 'v-if', but v-model just doesn't seem to work at all.

Nothing comes up in the console, and when using vue dev tools extension; I can see that the 'test' object is never updated when one of the radio buttons is selected.

I'm using the latest version of bootstrap, jquery and the vue development version.

<div class="container margin-top-rem" id="app">       
        <div class="row">
            <div class="col-12">
                <div class="card text-center" v-if="testIf">
                    <div class="tab-content" id="nav-tabContent">
                        <div class="tab-pane fade show active card-body-padding">
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group">
                                        <div class="btn-group btn-group-toggle" data-toggle="buttons">
                                            <label class="btn btn-secondary">
                                                <input type="radio" name="options" autocomplete="off" v-model="testVModel" :value="false" />false
                                            </label>
                                            <label class="btn btn-secondary">
                                                <input type="radio" name="options" autocomplete="off" v-model="testVModel" :value="true" />true
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div>test value is {{testVModel}}</div>
            </div>
        </div>
    </div>
 var app = new Vue({
   el: '#app',
   data: {
     testIf: 'blah',
     testVModel: ''
   }
 })

Solution

  • It looks like this is a conflict between bootstrap and Vue.

    Two options to resolve are:

    1) Use Bootstrap-vue

    2) Remove 'data-toggle="buttons"' from:

    <div class="btn-group-toggle" data-toggle="buttons">