Lzh on GitHub
Nuxt UI 与 Nuxt Icon 集成,可从 Iconify 访问超过 200,000+ 个图标。

用法

Nuxt UI 会自动为您注册 @nuxt/icon 模块,因此无需额外设置。

图标组件

您可以使用 Icon 组件和 name 属性来显示图标:

<template>
  <UIcon name="i-lucide-lightbulb" class="size-5" />
</template>
您可以使用 https://icones.js.org 集合中的任何名称。

组件 Props

某些组件也有一个 icon 属性来显示图标,例如 Button

<template>
  <UButton icon="i-lucide-sun" variant="subtle">Button</UButton>
</template>

集合

Iconify 数据集

强烈建议使用以下命令在本地安装图标数据:

pnpm i @iconify-json/{collection_name}

例如,要使用 i-uil-github 图标,请使用 @iconify-json/uil 安装其集合。这样,图标可以在本地或从您的无服务器函数中提供,这在 SSR 和客户端都更快、更可靠。

@nuxt/icon 文档中阅读有关此内容的更多信息。

自定义本地集合

您可以使用本地 SVG 文件创建自定义 Iconify 集合。

例如,将您的图标 SVG 文件放置在您选择的文件夹下,例如 ./app/assets/icons

assets/icons
├── add.svg
└── remove.svg

在您的 nuxt.config.ts 中,在 icon.customCollections 中添加一个项:

export default defineNuxtConfig({
  modules: ['@nuxt/ui'],
  css: ['~/assets/css/main.css'],
  icon: {
    customCollections: [{
      prefix: 'custom',
      dir: './app/assets/icons'
    }]
  }
})

然后您可以像这样使用图标:

<template>
  <UIcon name="i-custom-add" />
</template>
@nuxt/icon 文档中阅读有关此内容的更多信息。

Theme

您可以在 app.config.ts 中更改组件使用的默认图标:

app.config.ts
export default defineAppConfig({
  ui: {
    icons: {
      arrowLeft: 'i-lucide-arrow-left',
      arrowRight: 'i-lucide-arrow-right',
      check: 'i-lucide-check',
      chevronDoubleLeft: 'i-lucide-chevrons-left',
      chevronDoubleRight: 'i-lucide-chevrons-right',
      chevronDown: 'i-lucide-chevron-down',
      chevronLeft: 'i-lucide-chevron-left',
      chevronRight: 'i-lucide-chevron-right',
      chevronUp: 'i-lucide-chevron-up',
      close: 'i-lucide-x',
      ellipsis: 'i-lucide-ellipsis',
      external: 'i-lucide-arrow-up-right',
      file: 'i-lucide-file-text',
      folder: 'i-lucide-folder',
      folderOpen: 'i-lucide-folder-open',
      loading: 'i-lucide-loader-circle',
      minus: 'i-lucide-minus',
      plus: 'i-lucide-plus',
      search: 'i-lucide-search',
      upload: 'i-lucide-upload',
      arrowUp: 'i-lucide-arrow-up',
      arrowDown: 'i-lucide-arrow-down',
      caution: 'i-lucide-circle-alert',
      copy: 'i-lucide-copy',
      copyCheck: 'i-lucide-copy-check',
      dark: 'i-lucide-moon',
      error: 'i-lucide-circle-x',
      eye: 'i-lucide-eye',
      eyeOff: 'i-lucide-eye-off',
      hash: 'i-lucide-hash',
      info: 'i-lucide-info',
      light: 'i-lucide-sun',
      menu: 'i-lucide-menu',
      panelClose: 'i-lucide-panel-left-close',
      panelOpen: 'i-lucide-panel-left-open',
      reload: 'i-lucide-rotate-ccw',
      stop: 'i-lucide-square',
      success: 'i-lucide-circle-check',
      system: 'i-lucide-monitor',
      tip: 'i-lucide-lightbulb',
      warning: 'i-lucide-triangle-alert'
    }
  }
})