0
0
Vueframework~20 mins

Async components for lazy loading in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Async Vue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this Vue async component render initially?

Consider this Vue 3 async component setup using defineAsyncComponent:

import { defineAsyncComponent } from 'vue';

const AsyncComp = defineAsyncComponent(() => new Promise(resolve => {
  setTimeout(() => {
    resolve({ template: '
Loaded!
' }); }, 2000); })); export default { components: { AsyncComp }, template: '' }

What will the user see immediately after the component starts loading?

ANothing is rendered until the component finishes loading after 2 seconds.
BThe text 'Loading...' is shown automatically during the 2 seconds delay.
CAn empty space is rendered because no loading or error component is provided.
DThe component throws an error because the async component is not awaited.
Attempts:
2 left
💡 Hint

Think about what Vue shows by default if no loading or error component is specified.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a Vue async component with a loading message?

You want to create an async component that shows a loading message while fetching. Which code snippet correctly implements this?

A
const AsyncComp = defineAsyncComponent(() => import('./MyComp.vue'), {
  loadingComponent: { template: '<p>Loading...</p>' }
});
B
const AsyncComp = defineAsyncComponent({
  loader: () => import('./MyComp.vue'),
  loadingComponent: { template: '<p>Loading...</p>' }
});
C
const AsyncComp = defineAsyncComponent({
  loader: () => import('./MyComp.vue'),
  loading: { template: '<p>Loading...</p>' }
});
D
const AsyncComp = defineAsyncComponent(() => import('./MyComp.vue'), {
  loading: { template: '<p>Loading...</p>' }
});
Attempts:
2 left
💡 Hint

Check the property names expected by defineAsyncComponent when using an options object.

🔧 Debug
advanced
2:00remaining
Why does this async component cause a runtime error?

Look at this Vue async component definition:

const AsyncComp = defineAsyncComponent(() => {
  return import('./MyComp.vue').then(module => module.default);
});

When used, it throws: TypeError: module.default is not a constructor. Why?

ABecause the import returns a module object, but the component is exported as a named export, not default.
BBecause the import promise resolves to the component itself, not an object with a default property.
CBecause the arrow function lacks braces and does not return the promise correctly.
DBecause the async function returns the component instance instead of the component definition.
Attempts:
2 left
💡 Hint

Check how the component is exported in MyComp.vue.

state_output
advanced
2:00remaining
What is the rendered output after 3 seconds?

Given this Vue 3 component using async loading:

import { defineAsyncComponent, ref } from 'vue';

const AsyncComp = defineAsyncComponent({
  loader: () => new Promise(resolve => {
    setTimeout(() => resolve({ template: '
Async Loaded
' }), 2000); }), loadingComponent: { template: '
Loading...
' }, delay: 500 }); export default { components: { AsyncComp }, template: '' };

What will the user see after 3 seconds?

AThe text 'Loading...' because the loading component stays visible indefinitely.
BNothing is shown because the delay hides the loading component.
CAn error message because the async component failed to load.
DThe text 'Async Loaded' because the async component finished loading after 2 seconds.
Attempts:
2 left
💡 Hint

Consider the delay and loading time carefully.

🧠 Conceptual
expert
2:00remaining
Which statement about Vue async components is TRUE?

Choose the correct statement about Vue 3 async components and lazy loading.

AYou can specify error and timeout components to handle loading failures gracefully.
BAsync components always block rendering until fully loaded, causing UI freeze.
CAsync components cannot be used with suspense in Vue 3.
DLazy loading async components requires manual import and cannot use dynamic import syntax.
Attempts:
2 left
💡 Hint

Think about Vue 3 features for async components and error handling.