Vue3 Fundamentals · Rendering & Templates

Toggling with v-show

Toggling with v-show

A loading message should appear while data loads and vanish when it arrives. If the message is toggled often, mounting and removing it every time is more work than the job needs.

v-show hides an element by toggling its CSS display, leaving it in the DOM:

<p v-show="!loaded">Loading…</p>

When the expression is false, Vue sets display: none; when it is true, Vue restores the element's display. The element is always present — only its visibility changes. Like v-if, it takes an expression.

That is the difference from v-if. v-if adds and removes the element, so it starts fresh each time it appears. v-show keeps the element and its state, which makes it the cheaper choice for something you toggle often. Reach for v-if when the content is rarely shown or expensive to create.

Your job is to hide an element with v-show while keeping it in the DOM.

Challenge

The loading message stays on screen after loading finishes. Export an App component from App.vue that keeps the paragraph in the DOM but hides it with v-show when loaded is true.

The Test mounts your component, confirms the paragraph exists, and checks that it is not visible. The starter renders it plainly, so the Test fails — toggle it with v-show.

App.vue
<script setup>
const loaded = true;
</script>

<template>
  <p>Loading…</p>
</template>

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.