[Vuejs]-How do I correctly select all checkboxes?

1๐Ÿ‘

โœ…

I would prefer to keep things short and simple as much as possible

<v-checkbox
  :value="item.selected_values.length === item.filter_values.length"
  @change="item.selected_values = $event ? item.filter_values : []">
</v-checkbox>

item.selected_values = $event ? item.filter_values : []

This will set selected_values to filter_values for select all and [] for deselect all based all checkbox value ($event).

item.selected_values.length === item.filter_values.length

This will make the checkbox value recompute when selected_values changed.

Demo

๐Ÿ‘คUser 28

Leave a comment