更新记录
1.2.0(2026-10-15)
- 大幅扩充图标库:线性图标由 193 个增至 279 个,填充图标由 32 个增至 91 个
- 线性新增:几何形状(
hexagonoctagonpentagondiamondcircle-dot)、天气自然(sunrisesunsetcloud-drizzlecloud-lightningcloud-snowumbrellawindthermometerdropletsnowflakeleafflamewaves)、媒体(headphonesradiodiscshufflerepeatairplaytvlaptopgamepadwebcam)、设备(signalbattery-lowbattery-fullgaugehourglassinfinityrocketpalettemagnetlightbulbtrophycrowngem)、电商(storewalletbanknoteticketcalculator)、文件(file-minusfile-checkfile-xfile-codefolder-opensticky-notereceiptnewspaper)及方向 / 操作 / 状态补充图标 - 填充新增:方向箭头、校验 / 关闭 / 加减的圆形与方形、消息、日历时钟、锁、邮件、显示器 / 手机 / 平板、电池电源、奖杯王冠宝石灯泡等,均提供
-fill后缀 - 填充图标与线性图标名称成对覆盖,
filled属性可在线性名上直接切换实心
平台兼容性
uni-app(5.0)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | × | √ | √ | √ |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | × | × |
其他
| 多语言 | 暗黑模式 | 宽屏模式 | 蒸汽模式 |
|---|---|---|---|
| × | √ | √ | × |
hy-icon 纯CSS图标库
hy-icon 是一个 uni-app(Vue2 / Vue3) 的零依赖纯 CSS 图标组件:
- 图标以 SVG 路径内联在组件内部(
icons.js),不引入任何外部字体、图片或网络资源,打包体积可控、离线可用; - 通过 CSS
mask+background-color渲染,因此图标为矢量,可任意缩放不失真,颜色可由color属性或父级文字颜色(currentColor)随时切换; - 内置 270+ 线性图标 与 90+ 填充(实心)图标,涵盖几何、方向、操作、状态、媒体、天气、文件、设备系统、电商社交等场景;
- 支持
size、color、rotate、spin(loading 旋转)等能力。
示例页面见本工程
pages/icon/icon.vue。
功能特性
- 零外部依赖:无 iconfont、无图片、无 CDN,所有图形内联于
icons.js - 矢量渲染:基于 CSS
mask,任意size都清晰,颜色随color/currentColor变化 - 动态着色:不传
color时继承父级color,可与文字颜色保持一致 - 尺寸灵活:
size传数字按rpx,传字符串则原样使用(如20px、1.5em) - 旋转与动画:
rotate任意角度、spin无限旋转(适合 loading) - 线性 / 填充双风格:线性图标名后加
-fill即为对应的实心风格(如star→star-fill);也可用filled属性强制切换 - 易于扩展:在
components/hy-icon/icons.js的icons(线性)或fillIcons(填充)中按kebab-case增加一条 SVG 片段即可
安装
将 hy-icon 目录放入项目的 uni_modules 目录即可,组件已支持 easycom,无需手动 import。
基本用法
<template>
<view>
<!-- 基础 -->
<hy-icon name="home" />
<!-- 尺寸与颜色 -->
<hy-icon name="settings" :size="48" color="#3b7cff" />
<!-- 继承父级文字颜色 -->
<text style="color:#f43b3b">
<hy-icon name="heart" :size="32" />
</text>
<!-- loading 旋转 -->
<hy-icon name="loader" :size="40" color="#999999" spin />
<!-- 填充风格:名称加 -fill 后缀 -->
<hy-icon name="star-fill" :size="40" color="#f59e0b" />
<!-- 填充风格:也可用 filled 属性强制切换 -->
<hy-icon name="heart" :size="40" color="#f43b3b" filled />
<!-- 旋转角度 -->
<hy-icon name="chevron-right" :size="32" :rotate="90" />
<!-- 点击事件 -->
<hy-icon name="x" :size="36" @click="onClose" />
</view>
</template>
<script>
export default {
methods: {
onClose() {
uni.showToast({ title: '关闭', icon: 'none' })
}
}
}
</script>
属性 Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | String | '' | 图标名称(kebab-case),见下方图标清单;不存在时不渲染。填充图标使用 -fill 后缀 |
| size | Number / String | 40 | 图标尺寸。数字按 rpx,字符串原样(如 20px、1.5em) |
| color | String | '' | 图标颜色。为空时继承父级文字颜色(currentColor) |
| filled | Boolean | false | 强制使用填充(实心)风格。name="star" + filled 等价于 name="star-fill" |
| spin | Boolean | false | 是否无限旋转(常用于 loading) |
| rotate | Number | 0 | 旋转角度(deg),与 spin 同时使用时以外层旋转叠加动画 |
| customStyle | Object | {} | 透传到组件根节点的自定义样式 |
事件 Events
| 事件名 | 回调参数 | 说明 |
|---|---|---|
| click | event | 点击图标时触发 |
图标清单
线性图标(279 个)
按场景分类(名称即 name 取值):
几何形状
hexagon octagon pentagon diamond circle-dot circle square triangle
方向 / 导航
arrow-up arrow-down arrow-left arrow-right arrow-up-left arrow-up-right arrow-down-left arrow-down-right arrow-up-circle arrow-down-circle arrow-left-circle arrow-right-circle chevron-up chevron-down chevron-left chevron-right chevrons-up chevrons-down chevrons-left chevrons-right chevrons-up-down chevrons-left-right corner-up-left corner-up-right corner-down-left corner-down-right undo redo maximize minimize maximize-2 minimize-2 expand shrink move move-horizontal move-vertical rewind fast-forward navigation crosshair
操作
x plus minus check search menu more-horizontal more-vertical refresh-cw refresh-ccw refresh-cw-dot rotate-cw rotate-ccw edit edit-2 edit-3 trash trash-2 copy save share download upload filter sliders external-link link link-2 unlink clipboard clipboard-check clipboard-list paperclip scissors crop scan mouse-pointer toggle-left toggle-right
状态 / 提示
info alert-circle alert-circle-2 alert-triangle alert-octagon check-circle x-circle plus-circle minus-circle help-circle bell bell-off eye eye-off lock unlock shield shield-off loader loading check-square x-square plus-square minus-square message-plus user-circle smile frown meh
媒体
play play-circle pause pause-circle stop stop-circle skip-back skip-forward rewind fast-forward volume volume-1 volume-2 volume-x music disc radio headphones image camera video video-off film mic mic-off shuffle repeat airplay tv laptop gamepad webcam fullscreen cast
天气 / 自然
sun sunrise sunset cloud-drizzle cloud-lightning cloud-snow umbrella wind thermometer droplet snowflake leaf flame waves
文件 / 文档
file file-text file-plus file-minus file-check file-x file-code folder folder-plus folder-minus folder-open archive book book-open bookmark sticky-note receipt newspaper inbox layers package box
设备 / 系统
home user users user-plus user-minus user-check user-x settings grid list calendar clock star heart tag flag map map-pin phone phone-call mail message-circle message-square send wifi wifi-off signal bluetooth battery battery-low battery-full battery-charging power gauge hourglass infinity moon cloud cloud-off cloud-rain globe code terminal database server cpu monitor smartphone tablet watch printer hard-drive download-cloud upload-cloud key log-in log-out anchor feather rocket palette magnet lightbulb trophy crown gem award
电商 / 社交 / 数据
shopping-cart shopping-bag credit-card dollar-sign wallet banknote gift ticket store calculator truck thumbs-up thumbs-down at-sign hash compass zap target trending-up trending-down pie-chart bar-chart bar-chart-2 activity percent briefcase coffee
填充图标(91 个)
在线性名称后加 -fill 后缀:
- 几何形状:
circle-fillsquare-filltriangle-fillhexagon-filloctagon-fillpentagon-filldiamond-fillstar-fillheart-fillbookmark-fill - 方向 / 导航:
arrow-up-fillarrow-down-fillarrow-left-fillarrow-right-fillnavigation-fillfilter-fillzap-fill - 操作:
check-fillx-fillplus-fillminus-fillsend-fill - 状态 / 提示:
check-circle-fillx-circle-fillplus-circle-fillminus-circle-fillinfo-fillalert-circle-fillalert-triangle-fillcheck-square-fillx-square-fillplus-square-fillminus-square-fillmessage-plus-fillbell-fillshield-filluser-circle-fill - 媒体:
play-fillpause-fillstop-fillplay-circle-fillpause-circle-fillstop-circle-fillvideo-fillimage-fillcamera-fillvolume-fillmic-fillheadphones-fill - 文件 / 文档:
file-fillfile-text-fillfolder-fillbook-fillbook-open-fillarchive-filllayers-fillbox-fillpackage-fillclipboard-fill - 设备 / 系统:
home-filluser-fillmail-filllock-fillunlock-fillcalendar-fillclock-fillmonitor-fillsmartphone-filltablet-fillprinter-fillbattery-fillpower-fillmoon-fillcloud-fillmap-pin-fillmap-filltag-fillflag-filltrophy-fillcrown-fillgem-fillaward-filllightbulb-fill - 消息 / 社交:
message-circle-fillmessage-square-fillthumbs-up-fillthumbs-down-filleye-fill - 电商 / 金融:
shopping-bag-fillcredit-card-fillgift-fill
自定义扩展
在 uni_modules/hy-icon/components/hy-icon/icons.js 的 icons 对象中追加一条即可,值为 24×24 viewBox 的 SVG 内部片段:
export const icons = {
// ...
'my-icon': '<circle cx="12" cy="12" r="9"></circle><line x1="12" y1="7" x2="12" y2="12"></line>'
}
组件会自动注入
viewBox="0 0 24 24"等根属性:线性图标注入fill="none"、stroke="black"、stroke-width="2"、圆角线帽等;填充图标注入fill="black"、fill-rule="evenodd"(因此可在同一条path内通过子路径挖孔)。因此片段内只需书写形状本身,stroke/fill的颜色不影响显示(mask 只取形状)。
填充图标同样在 icons.js 的 fillIcons 对象中追加即可,键名建议以 -fill 结尾:
export const fillIcons = {
// ...
'my-icon-fill': '<path d="M12 2 2 22h20z"></path>'
}
平台支持
| 平台 | 支持情况 | 说明 |
|---|---|---|
| H5 / PC | √ | 浏览器原生支持 CSS mask |
| App(Android / iOS / HarmonyOS,vue 页面) | √ | 基于系统 WebView |
| 微信 / 支付宝 / 头条 / 百度 / 快手 / QQ / 飞书 / 小红书小程序 | √ | 基于小程序 WebView |
| App(nvue 页面) | x | nvue 不支持 CSS mask,请使用 vue 页面 |
| uni-app x / uvue | x | 原生渲染不支持 CSS mask |
注意事项
- 组件使用 CSS
mask-image指向内联 SVG data URI 实现,必须运行在 WebView 渲染环境(vue 页面 / H5 / 小程序);nvue 与 uni-app x 原生渲染不支持。 name传入不存在的图标名时组件不渲染任何内容,请在开发时核对名称(演示页可一键复制名称)。size传数字时按rpx处理;若需固定像素请传字符串,如size="24px"。- 深色模式下若未指定
color,图标会自动跟随父级文字颜色(currentColor),无需额外配置。 - 本组件不涉及输入框,无
input/textarea兼容性问题。

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 297
赞赏 1
下载 12684554
赞赏 1956
赞赏
京公网安备:11010802035340号