Performance: v-model with checkboxes
MEDIUM IMPACT
This affects how user input updates the UI and how Vue tracks checkbox states, impacting interaction responsiveness and rendering.
<template> <input type="checkbox" :value="item" v-model="selected" /> </template> <script setup> import { ref } from 'vue'; const selected = ref([]); </script>
<template> <input type="checkbox" :value="item" @change="updateSelection($event, item)" /> </template> <script setup> import { ref } from 'vue'; const selected = ref([]); function updateSelection(event, item) { if (event.target.checked) { selected.value.push(item); } else { selected.value = selected.value.filter(i => i !== item); } } </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual @change handler | Multiple array mutations and DOM updates | Multiple reflows per toggle | High paint cost due to repeated updates | [X] Bad |
| v-model binding | Single reactive update per toggle | Single reflow per toggle | Minimal paint cost | [OK] Good |