Complete the code to use v-memo with a single dependency.
<template> <div v-memo="[1]">Count: {{ count }}</div> </template> <script setup> import { ref } from 'vue' const count = ref(0) </script>
The v-memo directive expects an array of dependencies. Using [count.value] tracks the reactive value correctly.
Complete the code to memoize a list rendering with v-memo depending on items.
<template>
<ul>
<li v-for="item in items" :key="item.id" v-memo="[1]">{{ item.name }}</li>
</ul>
</template>
<script setup>
import { ref } from 'vue'
const items = ref([{ id: 1, name: 'A' }, { id: 2, name: 'B' }])
</script>.value.v-memo needs an array of reactive values. [items.value] correctly tracks the array's reactive state.
Fix the error in the v-memo usage to memoize based on user.name.
<template> <p v-memo="[1]">Hello, {{ user.name }}</p> </template> <script setup> import { reactive } from 'vue' const user = reactive({ name: 'Alice' }) </script>
v-memo requires an array of dependencies. Using [user.name] tracks changes to the name property.
Fill both blanks to memoize a component rendering based on count.value and status.
<template> <div v-memo="[[1], [2]]">Count: {{ count }}, Status: {{ status }}</div> </template> <script setup> import { ref } from 'vue' const count = ref(0) const status = 'active' </script>
count instead of count.value.Use count.value to track the reactive count and status as a normal variable in the dependency array.
Fill all three blanks to memoize a list rendering with v-memo based on items.value, filter, and searchTerm.
<template>
<ul>
<li v-for="item in filteredItems" :key="item.id" v-memo="[[1], [2], [3]]">{{ item.name }}</li>
</ul>
</template>
<script setup>
import { ref, computed } from 'vue'
const items = ref([{ id: 1, name: 'Apple' }, { id: 2, name: 'Banana' }])
const filter = ref('all')
const searchTerm = ref('')
const filteredItems = computed(() => {
return items.value.filter(item => {
return (filter.value === 'all' || item.name.includes(filter.value)) &&
item.name.toLowerCase().includes(searchTerm.value.toLowerCase())
})
})
</script>filteredItems directly in v-memo..value on refs.Memoize based on the reactive values items.value, filter.value, and searchTerm.value to update rendering correctly.