Performance: v-else and v-else-if
MEDIUM IMPACT
Controls conditional rendering in Vue, affecting how many DOM nodes are created and updated during rendering.
<template> <div v-if="status === 'loading'">Loading...</div> <div v-else-if="status === 'error'">Error!</div> <div v-else>Success!</div> </template>
<template> <div v-if="status === 'loading'">Loading...</div> <div v-if="status === 'error'">Error!</div> <div v-if="status === 'success'">Success!</div> </template>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple separate v-if | Multiple nodes created and destroyed | Multiple reflows per condition | Multiple paints | [X] Bad |
| v-if with v-else-if and v-else | Single node created/destroyed per render | Single reflow per update | Single paint | [OK] Good |