Consider a Vue component that mixes UI logic and data fetching directly inside the setup() without separation. What is the main impact on reusability?
<script setup> import { ref } from 'vue' const data = ref(null) fetch('/api/data').then(res => res.json()).then(json => data.value = json) </script> <template> <div>{{ data }}</div> </template>
Think about what happens if you want to use the component with different data sources.
Mixing data fetching directly inside the component ties it to a specific data source. This reduces reusability because you cannot easily change the data without modifying the component.
Given two components sharing the same reactive object without proper isolation, what will be the output after one updates the state?
<script setup> import { reactive } from 'vue' const sharedState = reactive({ count: 0 }) function increment() { sharedState.count++ } </script> <template> <button @click="increment">Increment</button> <p>Count: {{ sharedState.count }}</p> </template>
Consider what happens when multiple components use the same reactive object instance.
Sharing a reactive object means all components reference the same state. When one updates it, all reflect the change.
Which code snippet correctly shows a message only if isVisible is true?
The correct directive for conditional rendering in Vue is v-if.
v-if is the standard Vue directive for conditional rendering. The other options use invalid syntax.
Examine the code below. Why does the UI not update when count changes?
<script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value++ } </script> <template> <button @click="increment">Increment</button> <p>Count: {{ count }}</p> </template>
Think about how Vue tracks reactive state.
Vue only tracks reactive variables created with ref() or reactive(). Plain variables like let count = 0 are not reactive, so UI won't update.
In large Vue applications, why is it important to separate concerns like UI, state management, and side effects into different components or composables?
Think about teamwork and managing complexity in big projects.
Separating concerns helps keep code organized, easier to test, and allows teams to work on different parts without stepping on each other's toes.