0
0
Vueframework~10 mins

Why advanced patterns matter 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 create a reactive variable using Vue's Composition API.

Vue
<script setup>
import { [1] } from 'vue'
const count = [1](0)
</script>
Drag options to blanks, or click blank then click option'
Aref
Breactive
Ccomputed
Dwatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using reactive instead of ref for simple values
Trying to use computed without a getter function
2fill in blank
medium

Complete the code to watch a reactive variable and log its new value.

Vue
<script setup>
import { ref, [1] } from 'vue'
const count = ref(0)
[1](count, (newVal) => {
  console.log(newVal)
})
</script>
Drag options to blanks, or click blank then click option'
Awatch
Breactive
Ccomputed
DonMounted
Attempts:
3 left
💡 Hint
Common Mistakes
Using computed instead of watch for side effects
Trying to watch without importing watch
3fill in blank
hard

Fix the error in the code to correctly use a reactive object and update a property.

Vue
<script setup>
import { reactive } from 'vue'
const state = reactive({ count: 0 })
function increment() {
  state.[1]++
}
</script>
Drag options to blanks, or click blank then click option'
Acounter
Bnumber
Cvalue
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong property name like 'counter' or 'value'
Trying to increment the reactive object itself
4fill in blank
hard

Fill both blanks to create a computed property that doubles a reactive count.

Vue
<script setup>
import { ref, [1] } from 'vue'
const count = ref(5)
const double = [1](() => count.value [2] 2)
</script>
Drag options to blanks, or click blank then click option'
Acomputed
B*
C+
Dreactive
Attempts:
3 left
💡 Hint
Common Mistakes
Using reactive instead of computed
Using addition instead of multiplication
5fill in blank
hard

Fill all three blanks to create a reactive object, update a property, and watch the change.

Vue
<script setup>
import { [1], watch } from 'vue'
const state = [2]({ count: 0 })
watch(() => state.count, (newVal) => {
  console.log('Count changed to', newVal)
})
state.[3] = 10
</script>
Drag options to blanks, or click blank then click option'
Areactive
Ccount
Dref
Attempts:
3 left
💡 Hint
Common Mistakes
Using ref instead of reactive for objects
Updating a wrong property name