VueJS checkbox get Sum and count from data attribute value

 <tr v-for='(women, index) in womenServices' :key="index">
                        <td class="text-center" style="width: 30px;">
                            <div class="custom-control custom-checkbox d-inline-block">
                                <input type="checkbox" class="custom-control-input"
                                       :id="'chk_wm' + index"
                                       :name="'chk_wm' + index"
                                       :data-price="women.price"
                                       :checked="isChecked($event)"
                                       :value="women.id" v-model="womenPackageServices">
                                <label class="custom-control-label" :for="'chk_wm' + index"></label>
                            </div>
                        </td>
                        <td>
                            !{women.title}!
                        </td>
                        <td>
                            !{women.price}!
                        </td>
                    </tr>
<input type="text" class="form-control" :v-model="packageServicesSum" placeholder="Total Price" readonly>
const app = new Vue({
            el: '#addVueServices',
            delimiters: ['!{', '}!'],
            data: {
                womenPackageServices: [],
                packageServicesSum: 0,
            },
            methods: {
                }
            computed: {
                isChecked(event) {
                    var price = event.target.getAttribute('data-price');
                    this.packageServicesSum.push(price)
                }
            },
        })

v-model is working absolutely fine, getting id's and updating womenPackagesServices object But the problem is I want to get data attribute value to show SUM of Price and Count of selected Services. if there is another easy way to sum price, please help me out i also want to keep womenPackageServices because this array will be passed to database to store selected checkbox ids. i am not using any components etc and don't want to use.



Read more here: https://stackoverflow.com/questions/67391418/vuejs-checkbox-get-sum-and-count-from-data-attribute-value

Content Attribution

This content was originally published by azeemgujjar at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: