---
title: "<DevOnly>"
description: "使用 <DevOnly> 组件仅在开发环境中渲染组件。"
canonical_url: "https://nuxt.zhcndoc.com/docs/4.x/api/components/dev-only"
---
# <DevOnly>

> 使用 <DevOnly> 组件仅在开发环境中渲染组件。

Nuxt 提供 `<DevOnly>` 组件，用于仅在开发期间渲染组件。

该内容不会包含在生产构建中。

```vue [app/pages/example.vue]
<template>
  <div>
    <Sidebar />
    <DevOnly>
      <!-- this component will only be rendered during development -->
      <LazyDebugBar />

      <!-- if you ever require to have a replacement during production -->
      <!-- be sure to test these using `nuxt preview` -->
      <template #fallback>
        <div><!-- empty div for flex.justify-between --></div>
      </template>
    </DevOnly>
  </div>
</template>
```

## 插槽

- `#fallback`：如果你需要在生产环境中提供替代内容。

```vue
<template>
  <div>
    <Sidebar />
    <DevOnly>
      <!-- this component will only be rendered during development -->
      <LazyDebugBar />
      <!-- be sure to test these using `nuxt preview` -->
      <template #fallback>
        <div><!-- empty div for flex.justify-between --></div>
      </template>
    </DevOnly>
  </div>
</template>
```

---

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


## Sitemap

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