0
0
Vueframework~20 mins

Why templates matter in Vue - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Template Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this Vue template render?
Given the following Vue component template, what will be displayed in the browser?
Vue
<template>
  <div>
    <p>{{ message }}</p>
    <button @click="updateMessage">Click me</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
const message = ref('Hello')
function updateMessage() {
  message.value = 'Hello Vue!'
}
</script>
AInitially shows 'Hello'. After clicking the button, it changes to 'Hello Vue!'
BInitially shows 'Hello Vue!'. After clicking the button, it changes to 'Hello'.
CShows 'Hello' and clicking the button does nothing.
DShows nothing because the template is invalid.
Attempts:
2 left
💡 Hint
Think about how Vue's reactivity updates the displayed message when the button is clicked.
📝 Syntax
intermediate
1:30remaining
Which template syntax is correct for conditional rendering in Vue?
Choose the correct Vue template syntax to conditionally render a paragraph only if isVisible is true.
A<p v-if="isVisible">Visible</p>
B<p v-show="isVisible">Visible</p>
C<p v-else-if="isVisible">Visible</p>
D<p v-for="isVisible">Visible</p>
Attempts:
2 left
💡 Hint
Remember that v-if completely removes or adds the element based on the condition.
🔧 Debug
advanced
2:30remaining
Why does this Vue template fail to update the list?
Consider this Vue template and script. Why does adding a new item not update the displayed list?
Vue
<template>
  <ul>
    <li v-for="item in items" :key="item.id">{{ item.name }}</li>
  </ul>
  <button @click="addItem">Add Item</button>
</template>

<script setup>
import { reactive } from 'vue'
const items = reactive([{ id: 1, name: 'Apple' }, { id: 2, name: 'Banana' }])
function addItem() {
  items.push({ id: 3, name: 'Cherry' })
}
</script>
AThe key attribute is missing, so Vue cannot track list items properly.
BUsing reactive on an array does not make push reactive; use ref instead.
CThe addItem function is not called because the button has no click event.
DThe items array is not reactive because it is declared outside the script.
Attempts:
2 left
💡 Hint
Think about how Vue tracks changes in arrays with reactive vs ref.
🧠 Conceptual
advanced
2:00remaining
Why are Vue templates preferred over manual DOM manipulation?
Which reason best explains why Vue templates are better than manually changing the DOM with JavaScript?
ATemplates require more code but give full control over every DOM element.
BManual DOM manipulation is faster but harder to write, so templates are just for beginners.
CTemplates let Vue track changes and update only what is needed, improving performance and simplicity.
DManual DOM manipulation is deprecated and no longer works in modern browsers.
Attempts:
2 left
💡 Hint
Think about how Vue updates the page when data changes.
state_output
expert
2:30remaining
What is the final rendered output of this Vue component?
Analyze the following Vue component. What text will be shown after clicking the button twice?
Vue
<template>
  <div>
    <p>{{ count }}</p>
    <button @click="increment">Increment</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
const count = ref(0)
function increment() {
  count.value += 1
  if (count.value === 2) {
    count.value = 10
  }
}
</script>
AAfter two clicks, the displayed number is 0.
BAfter two clicks, the displayed number is 2.
CAfter two clicks, the displayed number is 1.
DAfter two clicks, the displayed number is 10.
Attempts:
2 left
💡 Hint
Check how the count changes on each click and the condition inside increment.