Consider a Vue store defined with reactive state. What happens when you update a property inside the state object?
import { reactive } from 'vue'; const store = { state: reactive({ count: 0 }) }; function increment() { store.state.count++; } increment(); console.log(store.state.count);
Think about how Vue's reactive function tracks changes.
Vue's reactive creates a reactive object. When you change a property like count, Vue tracks it and updates any component using that state.
Which of the following correctly defines a reactive state object inside a Vue store?
Remember the syntax for reactive requires an object inside parentheses.
Option D correctly uses reactive with an object. Option D uses ref which wraps a single value, not an object. Option D has syntax errors. Option D uses an array which is not typical for state objects.
Given this store code, why does the component not update when state.count changes?
import { reactive } from 'vue'; const state = { count: 0 }; function increment() { state.count++; } export default { state, increment };
Check how the state object is created and if Vue can track its changes.
The state object is a plain JavaScript object, not reactive. Vue cannot detect changes unless wrapped with reactive(). Option C is incorrect because numbers inside reactive objects are tracked. Option C is irrelevant. Option C is incorrect because reactive is appropriate for objects.
Given this Vue store code, what is the final value of state.items?
import { reactive } from 'vue'; const state = reactive({ items: [] }); function addItem(item) { state.items.push(item); } addItem('apple'); addItem('banana'); state.items = ['orange'];
Consider what happens when you assign a new array to a reactive property.
Initially, items array has 'apple' and 'banana'. Then it is replaced by a new array ['orange']. So the final value is ['orange'].
In Vue 3 stores, why is it recommended to define the state as a function returning an object instead of a plain object?
Think about what happens if multiple components use the same store instance.
Defining state as a function returning an object ensures each instance gets a fresh copy of the state. This prevents components from sharing and mutating the same state object, which can cause bugs. Vue does not require state to be functions, and functions do not automatically make state reactive or improve performance by caching.