0
0
Vueframework~10 mins

Why conditional rendering matters in Vue - Test Your Understanding

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

Complete the code to conditionally show the message only if isVisible is true.

Vue
<template>
  <div>
    <p v-if="[1]">Hello, Vue!</p>
  </div>
</template>
Drag options to blanks, or click blank then click option'
AisVisible
BshowMessage
Cvisible
Ddisplay
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined in the component.
Forgetting to use the correct variable controlling visibility.
2fill in blank
medium

Complete the code to toggle the visibility state when the button is clicked.

Vue
<script setup>
import { ref } from 'vue'
const isVisible = ref(false)

function toggle() {
  isVisible.value = [1]
}
</script>
Drag options to blanks, or click blank then click option'
Atrue
BisVisible
Cfalse
D!isVisible.value
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a fixed value like true or false instead of toggling.
Using isVisible without .value in the ref.
3fill in blank
hard

Fix the error in the template to correctly bind the click event to the toggle function.

Vue
<template>
  <button [1]="toggle">Toggle Message</button>
  <p v-if="isVisible">Now you see me!</p>
</template>
Drag options to blanks, or click blank then click option'
A@click
Bv-on:click.prevent
Cv-bind:click
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using v-bind:click which is incorrect for events.
Omitting the event binding syntax.
4fill in blank
hard

Fill both blanks to create a computed property that returns a message based on isVisible.

Vue
<script setup>
import { computed, ref } from 'vue'
const isVisible = ref(true)
const message = computed(() => [1] ? 'Visible' : [2])
</script>
Drag options to blanks, or click blank then click option'
AisVisible.value
B'Hidden'
CisVisible
D'Invisible'
Attempts:
3 left
💡 Hint
Common Mistakes
Using isVisible without .value.
Using the wrong string for the false case.
5fill in blank
hard

Fill all three blanks to create a reactive toggle button with conditional rendering and a dynamic message.

Vue
<template>
  <button [1]="[2]">Toggle</button>
  <p v-if="[3]">The message is visible.</p>
</template>

<script setup>
import { ref } from 'vue'
const visible = ref(false)
function toggle() {
  visible.value = !visible.value
}
</script>
Drag options to blanks, or click blank then click option'
A@click
Btoggle
Cvisible
DisVisible
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong event binding syntax.
Referencing a variable not defined in the script.