---
title: "<NuxtLoadingIndicator>"
description: "在页面导航之间显示进度条。"
canonical_url: "https://nuxt.zhcndoc.com/docs/3.x/api/components/nuxt-loading-indicator"
---
# \<NuxtLoadingIndicator>

> 在页面导航之间显示进度条。

## 使用方法

在 [`app.vue`](https://nuxt.zhcndoc.com/docs/3.x/directory-structure/app) 或 [`layouts/`](https://nuxt.zhcndoc.com/docs/3.x/directory-structure/layouts) 中添加 `<NuxtLoadingIndicator/>`。

```vue [app.vue]
<template>
  <NuxtLoadingIndicator />
  <NuxtLayout>
    <NuxtPage />
  </NuxtLayout>
</template>
```

::link-example{to="https://nuxt.zhcndoc.com/docs/examples/routing/pages"}
::

## 插槽

你可以通过加载指示器的默认插槽传入自定义的 HTML 或组件。

## 属性

- `color`：加载条的颜色。可以设置为 `false` 以关闭显式颜色样式。
- `errorColor`：当 `error` 设置为 `true` 时加载条的颜色。
- `height`：加载条的高度，单位为像素（默认 `3`）。
- `duration`：加载条的持续时间，单位为毫秒（默认 `2000`）。
- `throttle`：控制显示和隐藏的节流时间，单位为毫秒（默认 `200`）。
- `estimatedProgress`：默认情况下，Nuxt 会在接近 100% 时减速。你可以提供一个自定义函数来定制进度估计，该函数接收加载条的持续时间（上述）和经过时间，应该返回一个介于 0 到 100 之间的值。

::note
该组件是可选的。 :br
为了实现完全自定义，你可以基于 [它的源码](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-loading-indicator.ts) 实现你自己的加载指示器。
::

::note
你可以使用 [`useLoadingIndicator` composable](https://nuxt.zhcndoc.com/docs/3.x/api/composables/use-loading-indicator) 钩入底层的指示器实例，从而自行触发开始／结束事件。
::

::tip
加载指示器的速度在达到 `estimatedProgress` 控制的特定点后会逐渐减慢。此调整能更准确地反映较长页面加载时间，防止指示器过早显示 100% 完成。
::

---

- [源码](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-loading-indicator.ts)


## Sitemap

See the full [sitemap](https://nuxt.zhcndoc.com/sitemap.md) for all pages.
