Question 20
Given the following component setup, answer the given subquestions
Component: Task.vue
<template> <div> <button @click="toggleShowCompleted"> {{ showCompleted ? 'Hide' : 'Show' }} Completed </button>
<ul> <li v-for="task in filteredTasks" :key="task.id"> <span>{{ task.name }} - {{ task.status }}</span> <button @click="markComplete(task.id)">Mark Complete</button> </li> </ul>
<p>Total Completed: {{ completedCount }}</p> </div>
</template>
<script>export default { data() { return { showCompleted: false, tasks: [ { id: 1, name: 'Learn Vue', status: 'incomplete' }, { id: 2, name: 'Build Project', status: 'incomplete' }, { id: 3, name: 'Test App', status: 'complete' } ] }; }, computed: { filteredTasks() { if (this.showCompleted) return this.tasks; return this.tasks.filter(function (task) { return task.status !== 'complete'; }); }, completedCount() { return this.tasks.reduce(function (acc, task) { return acc + (task.status === 'complete' ? 1 : 0); }, 0); } }, methods: { markComplete(id) { const task = this.tasks.find(function (t) { return t.id === id; }); if (task && task.status === 'incomplete') { task.status = 'complete'; } }, toggleShowCompleted() { this.showCompleted = !this.showCompleted; } }};</script>Scenario
1. The component is loaded.
2. User clicks "Mark Complete" for the task named Build Project.
3. User clicks "Show Completed" button again.
After step 2 (Mark Completed is clicked), what tasks are shown?
Learn Vue
Learn Vue, Build Project, Test App
Test App only
None