Question 28
Consider the following Vue component structure with nested components and complex slot configurations:
Vue.component('data-provider', { template: ` <div class="provider"> <slot name="header" :user="currentUser" :loading="isLoading"></slot> <slot name="content" :items="filteredItems" :count="itemCount"></slot> <slot :fallback="defaultMessage" :error="errorState"></slot> </div> `, data() { return { currentUser: { name: 'John', role: 'admin' }, isLoading: false, filteredItems: ['item1', 'item2', 'item3'], itemCount: 3, defaultMessage: 'No data available', errorState: null } }});
Vue.component('parent-component', { template: ` <data-provider> <template v-slot:header="{ user, loading }"> <h1 v-if="!loading">Welcome {{ user.name }}</h1> <span v-else>Loading...</span> </template> <template v-slot:content="slotProps"> <ul> <li v-for="item in slotProps.items" :key="item"> {{ item }} ({{ slotProps.count }} total) </li> </ul> </template>
<template v-slot:default="defaultProps"> <p>{{ defaultProps.fallback }}</p> </template> </data-provider> `});Now consider this usage of the parent-component:
<div id="app"> <parent-component></parent-component></div>Assuming that the root Vue instance has already been created and mounted to div app. Which of the following statements are CORRECT?
The header slot will display "Welcome John" when loading is true
The content slot will render 3 list items with "item1 (3 total)", "item2 (3 total)", "item3 (3 total)"
The default slot will display "No data available" from the fallback prop
If we change isLoading: true in data-provider, the header will show "Loading..."
Changing v-slot:default to just v-slot in parent-component would break the functionality