在 Vue 中集成

在 Vue 3 项目中安装和使用 Univer Icons。

将图标加入 Vue 3 界面,然后调整尺寸和颜色,使其与周围控件保持一致。

安装图标包

在 Vue 3 项目中安装图标包:

Shell
pnpm add @univerjs/icons-vue

在按钮中添加图标

在图标预览中选择一个组件,并按组件名导入。下面的复制按钮将文字标签与图标并排显示。

Vue
<script setup lang="ts">import { CopyIcon } from '@univerjs/icons-vue'const emit = defineEmits<{ copy: [] }>()</script><template>  <button type="button" @click="emit('copy')">    <CopyIcon aria-hidden="true" />    <span>复制</span>  </button></template>

copy 事件由父组件处理。此处图标仅作装饰,因为可见文字已经说明了该操作。

调整尺寸和颜色

图标默认继承周围文字的颜色,尺寸取自 1em。在图标上设置 fontSize 和 color 即可覆盖这两个值:

Vue
<script setup lang="ts">import { AddImageIcon } from '@univerjs/icons-vue'</script><template>  <AddImageIcon    aria-hidden="true"    :style="{ fontSize: '20px', color: '#27272a' }"  /></template>

设置双色图标的配色

双色图标的主色由 color 设置,强调色由 extend.colorChannel1 设置。下面的示例以深灰为主色、浅灰为强调色:

Vue
<script setup lang="ts">import { PaintBucketDoubleIcon } from '@univerjs/icons-vue'</script><template>  <PaintBucketDoubleIcon    aria-hidden="true"    :style="{ fontSize: '20px', color: '#27272a' }"    :extend="{ colorChannel1: '#d4d4d8' }"  /></template>

多色图标(例如品牌标志)可能自带固定配色,这些设置不会替换此类图标中的全部颜色。

放大图标时保持描边宽度

图标放大后若线条显得过粗,可以使用 preserveStrokeWidth。支持该属性的描边会保持在 16 × 16 时的粗细,填充图形不受影响。应用前先在预览中切换“保持描边”控件,确认效果。

Vue
<script setup lang="ts">import { ShapePieIcon } from '@univerjs/icons-vue'</script><template>  <ShapePieIcon    aria-hidden="true"    preserve-stroke-width    style="font-size: 48px"  /></template>

为纯图标按钮添加名称

按钮没有可见文字时,在按钮上添加 aria-label="复制",并在图标上保留 aria-hidden="true",屏幕阅读器才能读出该操作。

如需由 AI Agent 查找图标并编写集成代码,可连接 MCP。

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.