[Vuejs]-Table bootstrap vue

1👍

Instead of a global value in your data, you should store the input value on each object.
That way it’s per-row.

new Vue({
  el: '#app',
  data() {
    return {
      fields: [
        'price',
        'quantity',
        'total'
      ],
      items: [{
          price: 550,
          quantity: 5,
          amount: 1
        },
        {
          price: 295,
          quantity: 16,
          amount: 1
        },
        {
          price: 199,
          quantity: 3,
          amount: 1
        }
      ]
    }
  }
})
<link href="https://unpkg.com/bootstrap@4.4.1/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://unpkg.com/bootstrap-vue@2.10.1/dist/bootstrap-vue.css" rel="stylesheet" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.10.1/dist/bootstrap-vue.min.js"></script>


<div id="app">
  <b-table :items="items" :fields="fields">
    <template #cell(quantity)="{ item }">
    	<b-input v-model="item.amount" min="1" :max="item.quantity" type="number" number></b-input>
    </template>
    <template #cell(total)="{ item }">
    	{{ item.price * (item.amount || 1)}}
    </template>
  </b-table>
</div>
👤Hiws

Leave a comment