Logo

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
biomousavi
Categories
4 categories in total
vue
open
nuxt
open
vif
open
webdev
open
Author
10 person written this
biomousavi
open
Why you should use both v-if and v-show to toggle heavy components in Vue ?

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 the DOM and only toggles the display 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>
Enter fullscreen mode Exit fullscreen mode

If we only use v-show, we don't have control on rendering and it will be rendered immediately(not displaying) without any conditions.

nuxt Article's
30 articles in total
Favicon
Resolving Auto-Scroll issues for overflow container in a Nuxt app
Favicon
Nuxflare Auth: A lightweight self-hosted auth server built with Nuxt, Cloudflare and OpenAuth.js
Favicon
The easiest way to migrate from Nuxt 3 to Nuxt 4!
Favicon
Creating a Scroll-Spy Menu with Nuxt 3 and Intersection Observer API
Favicon
Nuxt
Favicon
How to add comment from BlueSky to static/vue/nuxt project
Favicon
Navigation guards in Nuxt 3 with defineNuxtRouteMiddleware
Favicon
2024 Nuxt3 Annual Ecosystem Summary๐Ÿš€
Favicon
13 Vue Composables Tips You Need to Know
Favicon
Building a multi-lingual web app with Nuxt 3 and Nuxt i18n
Favicon
๐Ÿš€ Fetching and Displaying Data in Nuxt 3 with useAsyncData
Favicon
Nuxt File Storage Module reaching 2K Downloads per Month
Favicon
Why you should use both v-if and v-show to toggle heavy components in Vue ?
Favicon
How to Access a Child Componentโ€™s Ref with multi-root node (Fragment) in Vue 3
Favicon
Deploying Nuxt.js app to GitHubย pages
Favicon
Nuxt
Favicon
Add a Voice Search to your Nuxt3 App in 6 Easy Steps
Favicon
Nuxt.js in action: Vue.js server-side rendering framework
Favicon
@nuxt/test-utils - The First-Class Citizen for Nuxt Unit Testing
Favicon
Seamless Nuxt 2 Deployment: A Step-by-Step Guide with GitLab CI/CD and DigitalOcean
Favicon
Building Vhisper: Voice Notes App with AI Transcription and Post-Processing
Favicon
Easiest Way to Set Up GitHub Action CI/CD for Vue.js Apps
Favicon
Angular vs Next.js vs Nuxt.js: Choosing the Right Framework for Your Project
Favicon
Nuxt Authorization: How to Implement Team Role-Based Access Control in Nuxt 3
Favicon
Vue Fes Japan 2024
Favicon
๐Ÿ’ก Building a Nuxt 3 App with Pinia and Testing It with Cypress ๐Ÿš€
Favicon
Build a static website with Markdown content, using Nuxt and Fusionable (server API approach)
Favicon
Secure Your Nuxt 3 App
Favicon
Sending Emails in Nuxt 3: How I Handle Emails in My SaaS Boilerplate
Favicon
Build your new Storefront with Nuxt and Medusa 2.0.0

Featured ones: