通过 100+ 条技巧学习 Nuxt!

<DevOnly>

使用 <DevOnly> 组件仅在开发期间渲染组件。

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

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

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:如果您需要在生产环境中有替换内容。
<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>