Complete the code to define a computed property with a getter.
<script setup> import { ref, computed } from 'vue' const firstName = ref('John') const lastName = ref('Doe') const fullName = computed({ get() { return firstName.value + ' ' + [1].value } }) </script>
The getter returns the full name by combining firstName.value and lastName.value. So, lastName is the correct variable to use.
Complete the code to add a setter to the computed property.
<script setup> import { ref, computed } from 'vue' const firstName = ref('John') const lastName = ref('Doe') const fullName = computed({ get() { return firstName.value + ' ' + lastName.value }, set(value) { const names = value.split(' ') firstName.value = names[0] [1].value = names[1] } }) </script>
The setter splits the full name and assigns the second part to lastName.value. So, lastName is the correct variable to update.
Fix the error in the computed property setter to avoid runtime issues.
<script setup> import { ref, computed } from 'vue' const firstName = ref('Jane') const lastName = ref('Smith') const fullName = computed({ get() { return firstName.value + ' ' + lastName.value }, set(value) { const parts = value.split(' ') firstName.value = parts[0] [1] = parts[1] } }) </script>
The setter must assign to lastName.value to update the reactive reference. Assigning to lastName alone won't update the value.
Fill both blanks to create a computed property that capitalizes the full name and updates parts correctly.
<script setup> import { ref, computed } from 'vue' const firstName = ref('alice') const lastName = ref('johnson') const fullName = computed({ get() { return (firstName.value + ' ' + lastName.value).[1]() }, set(value) { const parts = value.split(' ') firstName.value = parts[0].[2]() lastName.value = parts[1].toLowerCase() } }) </script>
The getter capitalizes the full name using toUpperCase(). The setter capitalizes the first name with toLowerCase() to normalize the last name.
Fill all three blanks to create a computed property that reverses the full name and updates parts with trimming.
<script setup> import { ref, computed } from 'vue' const firstName = ref('Bob') const lastName = ref('Marley') const fullName = computed({ get() { return (lastName.value + ' ' + firstName.value).[1]().split('').reverse().join('') }, set(value) { const parts = value.split(' ').reverse() firstName.value = parts[0].[2]() lastName.value = parts[1].[3]() } }) </script>
The getter trims the combined string start with trimStart() before reversing. The setter trims the first name and uppercases the last name to normalize them.