Lucide Vue Next
用于 Lucide 图标的 Vue 3 组件,利用 Composition API 和现代 Vue 功能。每个图标都是一个响应式 Vue 组件,可渲染为内联 SVG,在 Vue 3 应用中提供卓越的性能和开发者体验。
¥Vue 3 components for Lucide icons that leverage the Composition API and modern Vue features. Each icon is a reactive Vue component that renders as an inline SVG, providing excellent performance and developer experience in Vue 3 applications.
你可以实现的目标:
¥What you can accomplish:
将图标用作 Vue 3 组件,并实现完全的响应式和 TypeScript 支持
¥Use icons as Vue 3 components with full reactivity and TypeScript support
将图标属性绑定到响应式数据和计算值
¥Bind icon properties to reactive data and computed values
使用 props、slots 和 Vue 强大的模板系统自定义图标
¥Customize icons with props, slots, and Vue's powerful templating system
与 Vue 3 的 Composition API 和脚本设置语法无缝集成
¥Integrate seamlessly with Vue 3's Composition API and script setup syntax
构建图标响应应用状态变化的动态界面
¥Build dynamic interfaces where icons respond to application state changes
安装
¥Installation
pnpm install lucide-vue-nextyarn add lucide-vue-nextnpm install lucide-vue-nextbun add lucide-vue-next如何使用
¥How to use
Lucide 基于 ES 模块构建,因此完全支持 tree-shaking。
¥Lucide is built with ES Modules, so it's completely tree-shakable.
每个图标都可以作为 Vue 组件导入,该组件会渲染一个内联 SVG 元素。这样,只有导入到项目中的图标才会包含在最终的软件包中。其余图标已通过 tree-shaking 移除。
¥Each icon can be imported as a Vue component, which renders an inline SVG Element. This way only the icons that are imported into your project are included in the final bundle. The rest of the icons are tree-shaken away.
示例
¥Example
你可以传递其他属性来调整图标。
¥You can pass additional props to adjust the icon.
<script setup>
import { Camera } from 'lucide-vue-next';
</script>
<template>
<Camera
color="red"
:size="32"
/>
</template>属性
¥Props
| name | type | default |
|---|---|---|
size | number | 24 |
color | string | currentColor |
stroke-width | number | 2 |
absoluteStrokeWidth | 布尔值 | false |
default-class | string | lucide-icon |
应用属性
¥Applying props
要自定义图标的外观,你可以将自定义属性作为 props 直接传递给组件。该组件接受所有 SVG 属性作为属性,从而允许灵活地设置 SVG 元素的样式。请参阅 MDN 上的 SVG 展示属性列表。
¥To customize the appearance of an icon, you can pass custom properties as props directly to the component. The component accepts all SVG attributes as props, which allows flexible styling of the SVG elements. See the list of SVG Presentation Attributes on MDN.
<template>
<Camera fill="red" />
</template>使用 Lucide Lab 或自定义图标
¥With Lucide lab or custom icons
Lucide Lab 是一个图标集合,不属于 Lucide 主库。
¥Lucide lab is a collection of icons that are not part of the Lucide main library.
它们可以通过 Icon 组件使用。所有与常规 Lucide 图标类似的属性都可以通过传递来调整图标外观。
¥They can be used by using the Icon component. All props like regular lucide icons can be passed to adjust the icon appearance.
使用 Icon 组件
¥Using the Icon component
这将根据传递的 iconNode 创建一个图标,并渲染一个 Lucide 图标组件。
¥This creates a single icon based on the iconNode passed and renders a Lucide icon component.
<script setup>
import { Icon } from 'lucide-vue-next';
import { baseball } from '@lucide/lab';
</script>
<template>
<Icon :iconNode="baseball" />
</template>一个通用图标组件
¥One generic icon component
可以创建一个通用的图标组件来加载图标,但不建议这样做。
¥It is possible to create one generic icon component to load icons, but it is not recommended.
危险
以下示例导入了所有 ES 模块,因此使用时请谨慎。导入所有图标将显著增加应用的构建大小,从而对其性能产生负面影响。在使用 Webpack、Rollup 或 Vite 等打包器时,这一点尤为重要。
¥The example below imports all ES Modules, so exercise caution when using it. Importing all icons will significantly increase the build size of the application, negatively affecting its performance. This is especially important when using bundlers like Webpack, Rollup, or Vite.
图标组件示例
¥Icon Component Example
<script setup>
import { computed } from 'vue';
import * as icons from "lucide-vue-next";
const props = defineProps({
name: {
type: String,
required: true
},
size: Number,
color: String,
strokeWidth: Number,
defaultClass: String
})
const icon = computed(() => icons[props.name]);
</script>
<template>
<component
:is="icon"
:size="size"
:color="color"
:stroke-width="strokeWidth" :default-class="defaultClass"
/>
</template>使用图标组件
¥Using the Icon Component
上面列出的所有其他属性也适用于 Icon 组件。
¥All other props listed above also work on the Icon Component.
<template>
<div id="app">
<Icon name="Airplay" />
</div>
</template>