dev-resources.site
for different kinds of informations.
Why you should use both v-if and v-show to toggle heavy components in Vue ?
Published at
12/31/2024
Categories
vue
nuxt
vif
webdev
Author
Nick Mousavi
Difference between v-if
and v-show
If you are a Vue.js developer, you might know what's the difference, if not, let's check:
v-if
: to Render a block conditionally.
v-show
: to Display a block conditionally.
v-show
renders once and remains in theDOM
and only toggles thedisplay
CSS property.
That means if you have a heavy component and rendering is expensive, you can render it once(v-if
) and toggle that ๐ฏ times without re-rendering(v-show
).
Example
<template>
<div v-if="isRendered">
<div v-show="isVisible">
<MyHeavyComponent/>
</div>
</div>
</template>
If we only use v-show, we don't have control on rendering and it will be rendered immediately(not displaying) without any conditions.
Articles
5 articles in total
Understanding Jitter Backoff: A Beginner's Guide
read article
How to Access a Child Componentโs Ref with multi-root node (Fragment) in Vue 3
read article
Why you should use both v-if and v-show to toggle heavy components in Vue ?
currently reading
Building a Production Stack: Docker, Meilisearch, NGINX & NestJS
read article
Easiest Way to Set Up GitHub Action CI/CD for Vue.js Apps
read article
Featured ones: