MertTheGreat
MertTheGreat

Reputation: 598

Two Way Binding Bootstrap-Vue Tables

I am trying to use two way data binding using v-model on bootstrap-vue table. But the value on the table does not change when the value changes.

I try to change data with a input text.

<template>
    <b-table striped hover :items="items" :fields="fields" v-model="items"></b-table>

    <span>The Value: {{value}} </span>
    <b-form-input v-model="value"></b-form-input>
</template>

<script>
  export default {
    data() {
      return {
        value = '',
        fields: ['field', 'value',],
        items: [
          { field: 'Field of Value', value: this.value},
        ]
      }
    }
  }
</script>

given value from form input changes the span text but does not change b-table value?

Upvotes: 1

Views: 1547

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

You should use items prop instead of v-model directive :

  <b-table striped hover  :fields="fields" :items="items"></b-table>

b-table items prop is one way binding.

You should use watch property in order to make that reactive :

 export default {
    data() {
      return {
        value : '',
        fields: ['field', 'value',],
        items: [
          { field: 'Field of Value', value: this.value},
        ]
      }
    },
   watch:{
   value(newVal){
   this.items[0].value=this.value;
    this.$set(this.items,0,this.items[0])

    }
  }
  }

Upvotes: 1

Related Questions