useFavoriteColor that accepts a parameter initialColor.color initialized with initialColor.updateColor inside the composable to change the color value.color and updateColor from the composable.useFavoriteColor that accepts a parameter initialColor.color initialized with initialColor.updateColor inside the composable to change the color value.color and updateColor from the composable.useFavoriteColor that accepts a parameter named initialColor. Inside it, create a reactive variable called color initialized with initialColor. Use Vue's ref to make color reactive.Use ref(initialColor) to create a reactive variable inside the composable.
useFavoriteColor composable, add a function called updateColor that accepts a parameter newColor and sets color.value to newColor. Return updateColor along with color.Define updateColor as a function that changes color.value.
<script setup>. Import useFavoriteColor and call it with the initial color 'blue'. Destructure color and updateColor from the composable. Display the current color inside a <p> tag and add a button that calls updateColor('red') when clicked.Use @click on the button to call updateColor('red').
aria-label attribute to the button with the value 'Change favorite color to red' for accessibility. Also, add a role="region" and aria-live="polite" to the <p> tag to announce color changes to screen readers.Use aria-label on the button and aria-live on the paragraph for accessibility.
What is the main purpose of passing parameters to a Vue composable function?
Which of the following is the correct way to define a composable that accepts a parameter initialCount?
function useCounter(???) {
const count = ref(initialCount)
return { count }
}initialCount must be declared inside the parentheses as initialCount.Given this composable and usage, what will be logged?
import { ref } from 'vue'
function useGreeting(name) {
const greeting = ref(`Hello, ${name}!`)
return { greeting }
}
const { greeting } = useGreeting('Alice')
console.log(greeting.value)name parameter, so the greeting string becomes "Hello, Alice!".greeting is a ref, so to get the string, we use greeting.value, which logs "Hello, Alice!".Identify the error in this composable that accepts a parameter start:
import { ref } from 'vue'
function useTimer(start) {
const time = ref(start)
function increment() {
time++
}
return { time, increment }
}.value property, so you cannot increment the ref itself.time.value++ instead of time++.You want a composable useFilteredList that accepts an array and a filter function as parameters. Which implementation correctly applies the filter reactively?
import { computed } from 'vue'
function useFilteredList(list, filterFn) {
const filtered = computed(() => ??? )
return { filtered }
}What should replace ????
list parameter is expected to be a ref(array) for proper reactivity in Vue composables.computed, access the array value with list.value.filter(filterFn) to apply the filter reactively whenever the list changes.Pass the test and this pattern moves unknown