reactive. What will be logged to the console after the update?import { reactive } from 'vue'; const state = reactive({ count: 0 }); console.log(state.count); state.count = 5; console.log(state.count);
The reactive function creates a reactive object. Initially, state.count is 0. After assignment, it updates to 5. So the console logs 0 first, then 5.
user.name. Which code snippet correctly does this?Using reactive on the outer object makes nested objects reactive automatically. Wrapping nested objects or properties with reactive or ref inside is unnecessary and can cause unexpected behavior.
state.user.age not update the UI?import { reactive } from 'vue'; const state = reactive({}); state.user = {}; // Later in code state.user.age = 30;
By assigning state.user = {}, state.user becomes a plain JavaScript object and not reactive. Adding new properties like age later does not trigger reactivity.
state.count after this code runs?state.count:import { reactive } from 'vue'; const state = reactive({ count: 1 }); function increment() { state.count += 1; } increment(); increment(); state.count = 10;
The function increment adds 1 twice, making count 3. Then state.count is set to 10, overwriting the previous value.
reactive behavior with nested objects?reactive function handles nested objects and property additions.Vue 3 uses Proxies to make reactive objects deeply reactive. This automatically tracks all nested objects and supports adding new properties dynamically at any time, which become reactive.