[Vuejs]-How to delete tbody(forms) were checked when I click button

0👍

Attach an event handler on the checkbox such that it will assign a value to global variable which will be used in the splice operation.

JS:

data: {
   selected: [];
}
methods: {
    checkedForm: function (index) {
        // check if checkbox is checked before pushing.
        this.selected.push(index);
    }

    dataPull: function () {
        if (this.selected.length < 1)
            return;

        this.selected.forEach((index) => { 
            this[dataType].splice(index, 1);
        }

        this.selected = [];
    }
};

HTML

<tbody v-for="(item, index)">
...
<input type="checkbox" v-on:change="checkedForm(index)"/>
...
</tbody>

0👍

you can use your inputParams(where you bind your checkboxes), it provides how many indexes checked or unchecked.

Leave a comment