0
0
Vueframework~10 mins

v-show vs v-if difference in Vue - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to use v-if to conditionally render the paragraph.

Vue
<template>
  <p [1]="isVisible">Hello Vue!</p>
</template>
Drag options to blanks, or click blank then click option'
Av-if
Bv-show
Cv-bind
Dv-for
Attempts:
3 left
💡 Hint
Common Mistakes
Using v-show when you want to remove the element from the DOM.
Confusing v-bind with conditional rendering.
2fill in blank
medium

Complete the code to use v-show to toggle visibility without removing the element from the DOM.

Vue
<template>
  <p [1]="isVisible">Hello Vue!</p>
</template>
Drag options to blanks, or click blank then click option'
Av-show
Bv-on
Cv-bind
Dv-if
Attempts:
3 left
💡 Hint
Common Mistakes
Using v-if when you want to keep the element in the DOM.
Confusing event directives like v-on with visibility control.
3fill in blank
hard

Fix the error in the code to correctly toggle the element visibility using v-show.

Vue
<template>
  <div>
    <p v-show="[1]">Visible Text</p>
    <button @click="toggle">Toggle</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
const isVisible = ref(true)
function toggle() {
  isVisible.value = !isVisible.value
}
</script>
Drag options to blanks, or click blank then click option'
AisVisible.value
BisVisible
Cvisible
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using isVisible.value inside the template, which causes errors.
Using a wrong variable name that is not defined.
4fill in blank
hard

Fill both blanks to create a Vue component that toggles visibility using v-if and a button click.

Vue
<template>
  <div>
    <p [1]="isVisible">Toggle me!</p>
    <button @click="[2]">Toggle</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
const isVisible = ref(true)
function toggle() {
  isVisible.value = !isVisible.value
}
</script>
Drag options to blanks, or click blank then click option'
Av-if
Btoggle
Cshow
Dv-show
Attempts:
3 left
💡 Hint
Common Mistakes
Using v-show instead of v-if when the question asks for v-if.
Using a wrong function name in the button click handler.
5fill in blank
hard

Fill all three blanks to create a Vue component that toggles visibility using v-show, a button click, and a reactive variable.

Vue
<template>
  <div>
    <p [1]="[2]">Show or hide me!</p>
    <button @click="[3]">Toggle</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
const isVisible = ref(true)
function toggle() {
  isVisible.value = !isVisible.value
}
</script>
Drag options to blanks, or click blank then click option'
Av-if
BisVisible
Ctoggle
Dv-show
Attempts:
3 left
💡 Hint
Common Mistakes
Using v-if instead of v-show when asked for v-show.
Using isVisible.value inside the template, which is incorrect.
Using a wrong function name in the button click handler.