Complete the code to import the Vue Composition API function needed to create a reactive reference.
import { [1] } from 'vue';
The ref function creates a reactive reference to a value in Vue's Composition API.
Complete the code to define a custom composable that returns a reactive count and an increment function.
export function useCounter() {
const count = [1](0);
function increment() {
count.value++;
}
return { count, increment };
}We use ref(0) to create a reactive count starting at zero.
Fix the error in the composable by completing the code to watch the count and log changes.
import { ref, watch } from 'vue'; export function useCounterLogger() { const count = ref(0); watch(count, (newVal, oldVal) => { console.log('Count changed from', [1], 'to', newVal); }); function increment() { count.value++; } return { count, increment }; }
The watch callback receives the old value directly as oldVal, no need for .value.
Fill both blanks to create a composable that returns a reactive message and a function to update it.
import { [1], [2] } from 'vue'; export function useMessage() { const message = ref('Hello'); function updateMessage(newMsg) { message.value = newMsg; } return { message, updateMessage }; }
We import ref to create reactive references and reactive is a common import but not used here. The correct imports are ref and reactive to match the options, but only ref is used in code.
Fill all three blanks to create a composable that returns a reactive count, an increment function, and a computed double count.
import { [1], [2], [3] } from 'vue'; export function useAdvancedCounter() { const count = ref(0); function increment() { count.value++; } const doubleCount = computed(() => count.value * 2); return { count, increment, doubleCount }; }
The correct imports are reactive, computed, and ref. Here, ref creates reactive values, computed creates derived reactive values, and reactive is often imported but not used in this snippet.