[{"id":"vueintermediate-001","courseId":"vue-intermediate","domain":"reactivity","topic":"Deep watchers","prompt":"A component watches a user object with a plain watch entry and no deep option. Later, code runs this.user.address.city = 'Lisbon'. Does the callback run?","hint":"Ask whether a default watcher sees changes deep inside an object or only changes to the property itself.","explain":"A watcher observes its source at one level unless you ask it to go deeper. Going deeper walks all nested values, which costs time on large data.","source":"https://vuejs.org/guide/essentials/watchers.html#deep-watchers","interaction":{"type":"single"},"options":[{"id":"a","text":"No. The callback runs only when user itself is assigned a new value.","why":"A default watch is shallow: it reacts to assignment of the watched property, not to nested property changes."},{"id":"b","text":"Yes. Vue watches every nested property of an object by default.","whyNot":"Deep tracking is opt-in. A watch on a property stays shallow unless deep: true is set."},{"id":"c","text":"Yes, but only if the callback is also marked immediate: true.","whyNot":"immediate runs the callback once on creation; it does not make the watcher traverse nested values."},{"id":"d","text":"Yes, but only if the watcher was created with flush: 'sync'.","whyNot":"flush controls when the callback runs, not how deep the watcher looks into the object."}],"answer":"a","explanation":"watch is shallow by default: its callback fires when the watched property is assigned a new value, not on nested property changes. deep: true opts in.","concept":"watch is shallow by default: its callback fires when the watched property is assigned a new value, not on nested property changes. deep: true opts in.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"watch: {\n  user () {\n    // runs on assignment\n  }\n}\n\nthis.user.address.city = 'Lisbon'","takeaways":["A default watch ignores nested edits. Add deep: true only when you need them, since traversing nested data is costly."]},{"id":"vueintermediate-002","courseId":"vue-intermediate","domain":"reactivity","topic":"Writable computed","prompt":"If a computed ref is created with both a getter and a setter, assigning to its .value runs the setter instead of the getter.","hint":"Think about what a computed needs in order to write back to other state.","explain":"A computed value is normally derived from other state and treated as read-only. A second function can be supplied to handle writes, and what Vue does on assignment depends on that.","source":"https://vuejs.org/guide/essentials/computed.html#writable-computed","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"Assignment calls the setter with the new value, and the setter can then update the refs the getter reads."},{"id":"b","text":"False","whyNot":"Assignment does not just overwrite a cached result; the setter is the function that runs on assignment."}],"answer":"a","explanation":"A computed with a setter runs that setter on assignment; a getter-only computed warns instead of accepting a write.","concept":"A computed with a setter runs that setter on assignment; a getter-only computed warns instead of accepting a write.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Use a writable computed only when a setter can push the value back into real state. Otherwise keep it getter-only."]},{"id":"vueintermediate-003","courseId":"vue-intermediate","domain":"reactivity","topic":"Mutating computed results","prompt":"A computed property visibleTodos filters a todos array, and a teammate wants to change what it returns. Which TWO of these follow Vue's guidance for computed properties?","hint":"Ask where a change belongs: in the computed's returned value, or in the state the computed reads.","explain":"A computed value is a cached result that Vue recalculates only when the state it read changes. Think about what the getter is allowed to do while it runs.","source":"https://vuejs.org/guide/essentials/computed.html#avoid-mutating-computed-value","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Change the source array the computed reads from, so the computed produces a new result.","why":"A computed return value is a snapshot, so you update the source state it depends on to trigger a new computation."},{"id":"b","text":"Keep the getter pure: compute and return the value without writing to other state.","why":"Computed getters should be free of side effects, so they only compute and return a value."},{"id":"c","text":"Push extra items into the array the computed returned; it stays changed until a dependency changes.","whyNot":"A computed return value is derived state that should be treated as read-only, so mutating it is wrong."},{"id":"d","text":"Set a flag or other state inside the getter so later reads are faster.","whyNot":"Getters must not mutate other state; the computed already caches its result on its own."},{"id":"e","text":"Fetch the data inside the getter and assign it to a ref when the response arrives.","whyNot":"Async requests are side effects, and they do not belong in a computed getter."},{"id":"f","text":"Mutate the returned array in place, and Vue will re-run the getter to pick up the change.","whyNot":"Editing the returned value does not change the computed's dependencies, so the getter does not re-run."}],"answer":"ab","explanation":"Computed getters must be pure, and a computed's returned value is read-only derived state; change the source state to get a new result.","concept":"Computed getters must be pure, and a computed's returned value is read-only derived state; change the source state to get a new result.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Computed getters stay side-effect free, and computed results are never mutated. Change the source state instead."]},{"id":"vueintermediate-004","courseId":"vue-intermediate","domain":"reactivity","topic":"toRefs for destructuring","prompt":"A composable returns reactive({ count: 0, step: 1 }). A component writes const { count } = useCounter(), and count stops updating in the template. How should the composable change what it returns?","hint":"Think about what a destructured primitive is, compared with a ref.","explain":"Destructuring copies each property's current value out of an object, so the link to the original property is lost. A ref is a wrapper that can stay connected to the property it came from.","source":"https://vuejs.org/api/reactivity-utilities.html#torefs","interaction":{"type":"single"},"options":[{"id":"a","text":"Return toRefs(state) instead of state","why":"toRefs converts each property into a ref linked to the original, so destructuring keeps reactivity."},{"id":"b","text":"Return Object.assign({}, state)","whyNot":"Copying the object copies its current values into plain properties, which are cut off from state."},{"id":"c","text":"Return shallowReactive(state)","whyNot":"Shallow reactivity changes how nested objects are handled; a destructured number is still a plain value."},{"id":"d","text":"Return state, and destructure with let instead of const","whyNot":"Choosing let over const does not change how destructuring copies values, so the link is still lost."}],"answer":"a","explanation":"toRefs turns each property of a reactive object into a ref linked to the original, so destructuring a returned object keeps reactivity.","concept":"toRefs turns each property of a reactive object into a ref linked to the original, so destructuring a returned object keeps reactivity.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Return toRefs(state) from composables so consumers can destructure the result without losing reactivity."]},{"id":"vueintermediate-005","courseId":"vue-intermediate","domain":"reactivity","topic":"Shallow refs track .value only","prompt":"In a shallowRef, assigning state.value.count = 2 re-runs a watchEffect that reads state.value.count.","hint":"Ask whether the inner object of a shallow ref is itself a reactive proxy.","explain":"A ref can either convert its value deeply into a reactive proxy or leave the value as-is. Shallow refs choose the second option, which changes what Vue can observe.","source":"https://vuejs.org/guide/essentials/reactivity-fundamentals.html#deep-reactivity","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The inner object of a shallow ref is not made reactive, so a nested write is not tracked and the effect does not re-run."},{"id":"b","text":"False","why":"Only access to .value is reactive, so the nested write goes unnoticed. Assigning a whole new object to .value does trigger effects."}],"answer":"b","explanation":"A shallow ref stores its value as-is; only .value reads and writes are reactive, so nested mutations are not tracked.","concept":"A shallow ref stores its value as-is; only .value reads and writes are reactive, so nested mutations are not tracked.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["With a shallowRef, replace .value to signal a change, or call triggerRef after a deep mutation."]}]