Question 19
Given the following parent-child component setup:
Parent Component: App.vue
<template> <div> <h2>Selected Tasks</h2> <task-list :tasks="tasks" @task-selected="addToSelection" /> <p>Total Selected: {{ selectedTasks.length }}</p> <ul> <li v-for="task in selectedTasks" :key="task.id">{{ task.name }}</li> </ul> </div></template>
<script>import TaskList from './TaskList.vue';
export default { components: { TaskList }, data() { return { tasks: [ { id: 1, name: 'Design UI' }, { id: 2, name: 'Write Backend' }, { id: 3, name: 'Write Tests' } ], selectedTasks: [] };
}, methods: { addToSelection(task) { const exists = this.selectedTasks.some(t => t.id === task.id); if (!exists) { this.selectedTasks.push(task); } } }};</script>Child Component: TaskList.vue
<template> <div> <h3>All Tasks</h3> <ul> <li v-for="task in tasks" :key="task.id"> {{ task.name }} <button @click="select(task)">Select</button> </li> </ul> </div></template>
<script>export default { props: ['tasks'], methods: { select(task) { this.$emit('task-selected', task); } }};</script>Test Scenario
- The app loads.
- User clicks "Select" on Design UI and Write Backend in order.
- User clicks "Select" on Design UI again.
Based on the above data, answer the given subquestions.
Which of the following statements about this component setup are true?