更新记录

1.0.0(2026-01-20) 下载此版本

1.0.0


平台兼容性

uni-app(4.83)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 快应用-华为 快应用-联盟

lrb-svg-icons

跨平台 SVG 图标组件库,支持 H5/小程序/App

特性

  • 跨平台兼容:H5 使用原生 <svg>,小程序使用 Base64 编码方案
  • easycom 自动引入:无需手动 import,直接使用
  • TypeScript 支持:完整的类型定义
  • 主题适配:默认使用 currentColor,自动继承父元素颜色
  • 按需加载:只打包使用的图标,减小包体积
  • 图标生成器:支持从 SVG 代码或 URL 快速生成新图标

安装

方式一:通过 uni_modules 导入(推荐)

  1. lrb-svg-icons 文件夹复制到项目的 src/uni_modules/ 目录
  2. 重启项目即可使用

方式二:通过 HBuilderX 插件市场

  1. 在 HBuilderX 中打开插件市场
  2. 搜索 "lrb-svg-icons"
  3. 点击导入

使用方式

基础用法

<template>
  <view>
    <!-- easycom 自动引入,无需 import -->
    <svg-home />
    <svg-user :size="64" />
    <svg-heart color="red" />
    <svg-sun :stroke-width="1.5" />
  </view>
</template>

Props 说明

属性 类型 默认值 说明
size number | string 48 图标大小(rpx)
color string 'currentColor' 图标颜色,默认继承父元素
strokeWidth number | string 2 线条粗细(仅 stroke 图标)
filled boolean false 是否填充(仅部分图标支持)

主题适配示例

<template>
  <view class="container">
    <!-- 自动继承父元素颜色 -->
    <svg-home />

    <!-- 使用 CSS 变量 -->
    <svg-user color="var(--primary)" />

    <!-- 直接指定颜色 -->
    <svg-heart color="#ef4444" />
  </view>
</template>

<style>
.container {
  color: var(--foreground);
}
</style>

支持 filled 的图标

部分图标支持 filled 属性,可以切换填充/描边状态:

<template>
  <view>
    <!-- 描边状态 -->
    <svg-heart />

    <!-- 填充状态 -->
    <svg-heart :filled="true" color="red" />

    <!-- 动态切换 -->
    <svg-bookmark :filled="isBookmarked" @click="toggleBookmark" />
  </view>
</template>

支持 filled 的图标:

  • svg-heart
  • svg-star
  • svg-bookmark

可用图标

导航和布局

  • svg-home - 首页
  • svg-layout-dashboard - 仪表板
  • svg-arrow-left - 左箭头
  • svg-chevron-up - 上箭头
  • svg-chevron-left - 左箭头(小)
  • svg-chevron-right - 右箭头(小)

媒体控制

  • svg-play - 播放
  • svg-pause - 暂停

用户和认证

  • svg-user - 用户
  • svg-lock - 锁定
  • svg-eye - 显示
  • svg-eye-off - 隐藏

内容和媒体

  • svg-book-open - 书籍
  • svg-clipboard-list - 清单
  • svg-camera - 相机
  • svg-image - 图片

社交和互动

  • svg-heart - 喜欢(支持 filled)
  • svg-star - 星标(支持 filled)
  • svg-bookmark - 书签(支持 filled)
  • svg-share - 分享
  • svg-message-square - 消息

商业和数据

  • svg-shopping-cart - 购物车
  • svg-store - 商店
  • svg-bar-chart - 柱状图

工具和设置

  • svg-sun - 太阳/亮色主题
  • svg-moon - 月亮/暗色主题
  • svg-palette - 调色板
  • svg-type - 文字
  • svg-phone - 电话
  • svg-calendar - 日历
  • svg-map-pin - 地图标记

第三方平台

  • svg-we-chat - 微信
  • svg-q-q - QQ
  • svg-alipay - 支付宝

其他

  • svg-alert-triangle - 警告

添加新图标

方式一:使用图标生成器

# 从 SVG 代码生成
node uni_modules/lrb-svg-icons/scripts/generate-icon.js \
  --name "arrow-right" \
  --svg '<svg>...</svg>'

# 从 URL 生成
node uni_modules/lrb-svg-icons/scripts/generate-icon.js \
  --name "arrow-right" \
  --url "https://example.com/icon.svg"

方式二:手动创建

  1. components/ 目录下创建新文件夹,如 svg-new-icon/
  2. 创建 svg-new-icon.vue 文件
  3. 参考现有图标的模板结构编写代码

补充说明

本插件内置图标有限,用户可根据上述方法轻松添加对应项目需要的图标。

平台兼容性

平台 支持情况 说明
H5 使用原生 <svg> 标签
微信小程序 使用 Base64 编码
支付宝小程序 使用 Base64 编码
百度小程序 使用 Base64 编码
字节跳动小程序 使用 Base64 编码
QQ 小程序 使用 Base64 编码
App (Vue) 使用 Base64 编码

技术原理

H5 平台

直接使用 SVG 标签,支持 CSS 样式控制,性能最优。

小程序平台

由于小程序不支持直接使用 SVG 标签,采用以下方案:

  1. 将 SVG 代码转换为 Base64 编码
  2. 使用 <image> 组件显示
  3. 通过动态生成 SVG 字符串实现颜色和尺寸控制

注意事项

  1. 颜色继承:默认使用 currentColor,会继承父元素的 color 样式
  2. 尺寸单位size 属性使用 rpx 单位,自动适配不同屏幕
  3. 小程序限制:小程序中 currentColor 会被替换为 #0f172a(深色)
  4. 性能优化:只会打包使用的图标,未使用的图标不会增加包体积

更新日志

查看 CHANGELOG.md

许可证

MIT License

相关链接

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT License

Copyright (c) 2026 L.R.B

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

暂无用户评论。