Performance: Attribute binding with v-bind
MEDIUM IMPACT
This affects how efficiently Vue updates HTML attributes in the DOM during reactive data changes.
<template> <button :disabled="isDisabled" @click="toggle">Click me</button> </template> <script setup> import { ref } from 'vue'; const isDisabled = ref(false); function toggle() { isDisabled.value = !isDisabled.value; } </script>
<template> <button id="btn" :disabled="isDisabled" @click="toggle">Click me</button> </template> <script setup> import { ref } from 'vue'; const isDisabled = ref(false); function toggle() { const btn = document.getElementById('btn'); if (btn.hasAttribute('disabled')) { btn.removeAttribute('disabled'); } else { btn.setAttribute('disabled', ''); } } </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual DOM attribute manipulation | Multiple direct DOM queries and updates | 2+ reflows per update | High paint cost due to layout thrashing | [X] Bad |
| Vue v-bind reactive attribute binding | Single reactive update with batched DOM patch | 1 reflow per update | Lower paint cost due to efficient updates | [OK] Good |