Complete the code to conditionally render the paragraph only if show is true.
<template> <p v-if="[1]">Hello Vue!</p> </template>
The v-if directive checks the value of show to decide if the paragraph should appear.
Complete the code to toggle the show variable when the button is clicked.
<template> <button @click="[1]">Toggle</button> <p v-if="show">Visible Text</p> </template> <script setup> import { ref } from 'vue' const show = ref(false) function toggle() { show.value = !show.value } </script>
The button's click event calls the toggle() function to change show.
Fix the error in the template to correctly use v-if with the reactive variable show.
<template> <p v-if="[1]">Conditional Text</p> </template> <script setup> import { ref } from 'vue' const show = ref(true) </script>
show without .value in script but not in template.show as a function.In the template, you must use show.value to access the reactive value inside ref.
Fill both blanks to create a v-if that shows the message only if isLoggedIn is true and hasAccess is true.
<template> <p v-if="[1] && [2]">Welcome back!</p> </template> <script setup> import { ref } from 'vue' const isLoggedIn = ref(true) const hasAccess = ref(false) </script>
|| instead of &&.Both isLoggedIn and hasAccess must be true for the message to show.
Fill all three blanks to create a dictionary comprehension that maps each item to its length only if the length is greater than 3.
<script setup> const items = ['apple', 'bat', 'carrot', 'dog'] const result = { [1]: [2] for [3] in items if [2] > 3 } </script>
This creates an object where each item is a key and its length is the value, but only for items longer than 3 characters.