简体   繁体   中英

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?

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])

    }
  }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM