Performance: v-model with radio buttons
MEDIUM IMPACT
This affects how user input updates the UI and how Vue manages DOM updates for radio button groups.
<template> <input type="radio" value="option1" v-model="selected" /> Option 1 <input type="radio" value="option2" v-model="selected" /> Option 2 </template> <script setup> import { ref } from 'vue' const selected = ref(null) </script>
<template> <input type="radio" value="option1" :checked="selected === 'option1'" @change="selected = $event.target.value" /> Option 1 <input type="radio" value="option2" :checked="selected === 'option2'" @change="selected = $event.target.value" /> Option 2 </template> <script setup> import { ref } from 'vue' const selected = ref(null) </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual @change handlers on each radio | Multiple event listeners | Multiple reflows if state triggers broad updates | Higher paint cost due to extra layout recalculations | [X] Bad |
| v-model binding on radio buttons | Single reactive binding per input | Minimal reflows limited to changed input | Lower paint cost due to targeted updates | [OK] Good |