Consider this Vue 3 component using the Composition API. What will be the displayed count after clicking the button two times?
<template> <button @click="increment">Click me</button> <p>Count: {{ count }}</p> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value++ } </script>
Remember that ref creates a reactive value that updates the UI when changed.
Each click calls increment, which increases count.value by 1. After two clicks, count is 2, so the displayed text is 'Count: 2'.
Given this Vue 3 code snippet, what will be the value of state.message after calling updateMessage()?
<script setup> import { reactive } from 'vue' const state = reactive({ message: 'Hello' }) function updateMessage() { state.message = 'Hi' } updateMessage() </script>
Reactive objects update their properties reactively when assigned new values.
Calling updateMessage() sets state.message to 'Hi'. So the value is 'Hi'.
Look at this Vue 3 code snippet. The UI does not update after pushing a new item to the array. Why?
<script setup> import { shallowReactive } from 'vue' const state = shallowReactive({ items: [] }) function addItem() { state.items.push('new') } addItem() </script>
Think about shallowReactive vs reactive and how Vue tracks changes in nested arrays.
shallowReactive only proxies the top-level properties. The nested items array remains a plain JavaScript array, so mutations like push() do not trigger reactivity updates or UI re-renders. Use reactive for deep reactivity on nested data structures.
Vue 3 uses Proxy for reactivity instead of Object.defineProperty like Vue 2. What is the main advantage of this change?
Think about what Proxy can do that Object.defineProperty cannot.
Proxy can intercept operations like adding or deleting properties, which Object.defineProperty cannot track. This makes Vue 3's reactivity more flexible and complete.
Choose the correct Vue 3 Composition API syntax to create a computed property doubleCount that returns count * 2, where count is a ref.
Remember to access the value inside a ref with .value.
Since count is a ref, you must use count.value inside the computed function. Option B correctly does this. Option B and D forget .value, and C passes an expression instead of a function.