Performance: v-once for static content
MEDIUM IMPACT
This affects the rendering speed by skipping future updates for static parts of the UI, reducing CPU work during re-renders.
<template>
<div v-once>
<h1>{{ title }}</h1> <!-- title never changes -->
</div>
</template>
<script setup>
const title = 'Welcome to Vue'
</script><template>
<div>
<h1>{{ title }}</h1> <!-- title never changes -->
</div>
</template>
<script setup>
const title = 'Welcome to Vue'
</script>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Without v-once | Re-renders virtual DOM nodes every update | Triggers reflows if DOM changes | Paint cost depends on changes | [X] Bad |
| With v-once | Renders DOM nodes once, skips updates | No reflows from static content on updates | Paint cost only on initial render | [OK] Good |