Skip to content

vue-async-component ​

defineAsyncComponent(...) without an errorComponent or onError.

Why: an async component is downloaded when it is first shown, and downloads fail: a flaky connection, or a deploy that replaced the file the old page asks for. Without an error component, Vue shows nothing in its place and the error only reaches the console. The user sees a hole in the page. Guide: Vue.

vue
<script setup lang="ts">
import { defineAsyncComponent } from "vue";

const SalesChart = defineAsyncComponent(() => import("./SalesChart.vue"));
</script>

<template>
  <SalesChart />
</template>
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { defineAsyncComponent } from "vue";
import LoadFailed from "./LoadFailed.vue";

const SalesChart = defineAsyncComponent({
  loader: () => import("./SalesChart.vue"),
  errorComponent: LoadFailed,
  onError(error, retry, fail, attempts) {
    if (attempts <= 3) retry();
    else fail();
  },
});
</script>

<template>
  <SalesChart />
</template>

errorComponent is shown when loading fails; onError decides whether to try again first.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra