更新记录
1.4.0(2026-10-04) 下载此版本
- 新增 14 个基础表单组件(分批第 2 批):
simple-input输入框:类型(text/number/digit/password/idcard)、清空、字数统计、 前后置图标与插槽、三种边框模式、错误态与必填标记simple-textarea文本域:自动增高、字数统计、固定高度simple-inputnumber数字输入框:步进、范围收敛、精度控制simple-search搜索框:圆角 / 方形、清空、右侧操作区插槽simple-radio-group/simple-radio单选框:横向纵向、禁用、形状、选中色simple-checkbox-group/simple-checkbox复选框:最大勾选数(超出触发overflow)simple-switch开关:三档尺寸、状态文字与配色、加载态simple-slider滑块:单滑块与双滑块区间、步长吸附、拖动回调simple-rate评分:半星、自定义星星数与配色、右侧分值simple-upload上传:选择、自动上传(带进度)、删除、预览、数量限制simple-form/simple-form-item表单校验(见下)
- 新增表单校验体系
- 规则支持
required/min/max/pattern/ 自定义validator(validator支持返回false、错误信息字符串、或Promise) - 方法:
validate()、validateField(prop)、clearValidate()、resetFields() - 值变化时自动清除该字段的错误提示,用户改正后不会一直显示红字
- 多字段并行校验,提升长表单响应速度
resetFields()恢复到字段注册时的初始值(数组 / 对象做浅拷贝)- FormItem 插槽:
label、默认(作用域{ value, error })、error
- 规则支持
libs/theme.scss补充表单类主题变量(输入框、单选复选、开关、滑块、 评分、表单标签与错误、上传)index.js注册全部 27 个组件;库 readme 补齐各组件 API 表与校验规则说明- demo 页「表单组件」分组扩到 12 项,新增 11 个演示区块
关键实现说明
simple-inputnumber:输入过程中不立即收敛,失焦时才做范围与精度处理, 避免打断输入;用toFixed处理浮点误差(如0.1 + 0.2)simple-rate半星:把每颗星拆成左右两个触摸区,不依赖坐标计算(更可靠)simple-slider:触摸热区上下各留 24rpx,把细轨道的可点区域撑到 56rpx; 双滑块拖动自动判断目标并保证start <= endsimple-radio/simple-checkbox:label是值,显示文字用text或默认插槽
1.2.9(2026-10-04) 下载此版本
package.json的displayName改为原名 + 简介内容去掉标点符号的版本- 与
description信息保持一致,便于插件市场的检索匹配 - 去掉中英文标点(
,。、()/等),并合并多余空格 - 当前长度 100 字
- 与
1.2.6(2026-10-04) 下载此版本
新增 预览图
查看更多平台兼容性
uni-app(5.0)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| × | √ | √ | √ | √ | × | √ | √ | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | √ | × | √ | √ | √ | × | × |
simple-ui 简约组件库
一套基于 uni-app + Vue3 的 UI 组件库,覆盖大部分复杂业务应用场景,组件可直接投入使用,无需二次封装。
特性
- 面向业务场景设计:组件能力覆盖表单、选择、反馈等常见复杂业务需求,拿来即用
- 全平台兼容:App(Android / iOS)、H5、微信 / 支付宝 / 头条 / 百度 / 快手 / 京东 / QQ / 飞书 / 小红书 小程序
- easycom 按需引入:无需 import,直接用标签,不用的组件不会打包进产物
- SCSS 变量主题:覆盖变量即可整库换肤
- BEM 命名:
sui-前缀,不污染你的全局样式
安装
方式一:插件市场导入(推荐)
- 在 HBuilderX 中打开你的项目
- 访问 DCloud 插件市场,搜索 simple-ui
- 点击「下载插件并导入 HBuilderX」,选择你的项目
导入后组件会出现在你项目的 uni_modules/simple-ui 目录下,无需任何额外配置。
后续更新:右键 uni_modules/simple-ui 目录 → 更新插件。
方式二:手动拷贝
把整个 simple-ui 目录拷贝到你项目的 uni_modules/ 下即可。
目录名必须保持为
simple-ui,改名会导致 easycom 失效。
环境要求
| 项 | 要求 |
|---|---|
| uni-app | Vue3 |
| HBuilderX | ≥ 3.1.0 |
| SCSS | 需开启(HBuilderX 需安装 sass 插件) |
快速开始
插件内置 easycom 规则,无需 import 和注册,直接在页面里使用:
<template>
<view>
<simple-button text="提交" type="primary" @click="onSubmit" />
</view>
</template>
<script>
export default {
methods: {
onSubmit() {
uni.showToast({ title: '已提交', icon: 'none' })
}
}
}
</script>
全局注册(可选)
想一次性注册全部组件时使用:
// main.js
import { createSSRApp } from 'vue'
import App from './App.vue'
import SimpleUI from '@/uni_modules/simple-ui'
export function createApp() {
const app = createSSRApp(App)
app.use(SimpleUI)
return { app }
}
按需手动引入(可选)
需要在代码里持有组件引用时使用:
<script>
import { SimpleButton } from '@/uni_modules/simple-ui'
export default {
components: { SimpleButton }
}
</script>
主题定制
组件内部所有颜色、尺寸都使用 !default 变量。在你项目的 uni.scss 中先引入主题文件、再声明覆盖值:
// uni.scss
@import '@/uni_modules/simple-ui/libs/theme.scss';
/* 覆盖主色 */
$sui-color-primary: #ff6b00;
/* 覆盖圆角 */
$sui-radius-base: 20rpx;
变量声明顺序必须在
@import之后,因为 SCSS 后声明的变量覆盖先声明的。
常用变量
| 变量 | 默认值 | 说明 |
|---|---|---|
$sui-color-primary |
#2979ff |
主色 |
$sui-color-success |
#19be6b |
成功色 |
$sui-color-warning |
#ff9900 |
警告色 |
$sui-color-error |
#fa3534 |
错误色 |
$sui-color-info |
#909399 |
信息色 |
$sui-text-color |
#303133 |
主文字色 |
$sui-text-color-content |
#606266 |
正文文字色 |
$sui-text-color-tips |
#909399 |
辅助文字色 |
$sui-bg-color |
#ffffff |
组件背景色 |
$sui-bg-color-mask |
rgba(0,0,0,.45) |
遮罩色 |
$sui-border-color |
#e4e7ed |
边框色 |
$sui-radius-base |
12rpx |
基础圆角 |
$sui-height-base |
76rpx |
基础高度 |
$sui-font-size-base |
28rpx |
基础字号 |
$sui-form-height |
88rpx |
表单控件高度 |
$sui-placeholder-color |
#c0c4cc |
占位文字色 |
$sui-selected-color |
#2979ff |
选中态文字 / 对勾色 |
$sui-option-height |
96rpx |
选择器选项高度 |
$sui-option-selected-bg |
#f5f9ff |
选择器选中项背景 |
$sui-zindex-popup |
999 |
弹层层级 |
$sui-zindex-mask |
998 |
遮罩层级 |
组件列表
simple-button 按钮
常用的操作按钮,支持 6 种类型、3 种尺寸与多种状态。
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
text |
String | '' |
按钮文字(也可用默认插槽) |
type |
String | primary |
primary / success / warning / error / info / default |
size |
String | default |
small / default / large |
plain |
Boolean | false |
朴素(描边)样式 |
round |
Boolean | false |
圆角样式 |
block |
Boolean | false |
通栏(占满一行) |
disabled |
Boolean | false |
禁用 |
loading |
Boolean | false |
加载中 |
loadingText |
String | '' |
加载中显示的文案,不传则沿用 text |
color |
String | '' |
覆盖文字颜色 |
bgColor |
String | '' |
覆盖背景色(plain 模式下不生效) |
插槽 / 事件
| 名称 | 类型 | 说明 |
|---|---|---|
default |
插槽 | 按钮内容,优先级高于 text |
icon |
插槽 | 图标区域 |
click |
事件 | 点击按钮(禁用 / 加载中不触发) |
用法
<simple-button text="主要" type="primary" />
<simple-button text="成功" type="success" />
<simple-button text="朴素" plain />
<simple-button text="圆角" round />
<simple-button text="禁用" disabled />
<simple-button text="加载中" loading />
<simple-button text="通栏" block @click="onClick" />
simple-icon 图标
内置常用符号集,支持图片图标与图标字体接入。
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
name |
String | '' |
图标名,取内置符号集 |
size |
String / Number | '' |
尺寸,数字按 rpx;不传用主题变量 |
color |
String | '' |
图标颜色 |
src |
String | '' |
图片图标地址,传了优先用图片 |
customPrefix |
String | '' |
图标字体类名前缀,渲染为 ${customPrefix}${name} |
clickable |
Boolean | false |
是否有点击态 |
事件:click
<simple-icon name="success" size="40" color="#19be6b" />
<simple-icon name="search" size="40" />
<!-- 接入自己的图标字体 -->
<simple-icon name="home" custom-prefix="iconfont icon-" size="40" />
<!-- 图片图标 -->
<simple-icon src="/static/logo.png" size="48" />
组件库不内置图标字体(避免体积膨胀与版权问题),内置符号集仅覆盖常用图标。 完整图标集请用
customPrefix接入自己的字体,或用src/ 默认插槽。
simple-image 图片
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
src |
String | '' |
图片地址 |
mode |
String | aspectFill |
裁剪模式,同 uni-app image |
width |
String / Number | 100% |
宽度,数字按 rpx |
height |
String / Number | 240 |
高度,数字按 rpx |
radius |
String / Number | 0 |
圆角(rpx) |
lazyLoad |
Boolean | true |
懒加载(小程序端生效) |
preview |
Boolean | false |
点击是否全屏预览 |
previewList |
Array | [] |
预览图列表,不传则只预览当前图 |
事件:load、error、click
插槽:placeholder(加载中占位)、error(失败占位)
<simple-image src="/static/logo.png" :width="110" :height="110" :radius="12" />
<simple-image src="/static/logo.png" :width="110" :height="110" preview />
simple-avatar 头像
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
src |
String | '' |
图片地址 |
size |
String / Number | default |
small / default / large,或直接传数字(rpx) |
shape |
String | circle |
circle 圆形 / square 方形 |
icon |
String | '' |
图标名(无 src 时生效) |
text |
String | '' |
文字(取首字展示) |
bgColor |
String | '' |
背景色 |
color |
String | '' |
文字 / 图标颜色 |
事件:click、error 插槽:默认
<simple-avatar src="/static/logo.png" size="large" />
<simple-avatar text="张" bg-color="#2979ff" />
<simple-avatar icon="user" bg-color="#19be6b" />
<simple-avatar src="/static/logo.png" shape="square" />
simple-badge 徽标
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
value |
String / Number | '' |
徽标数值,非数字则原样展示 |
max |
String / Number | 99 |
数值上限,超出显示 ${max}+ |
dot |
Boolean | false |
显示为小圆点(忽略 value) |
show |
Boolean | true |
是否显示 |
color |
String | '' |
背景色 |
textColor |
String | '' |
文字颜色 |
插槽:默认(徽标依附的内容)
<simple-badge :value="5"><view>消息</view></simple-badge>
<simple-badge :value="120" :max="99"><view>上限</view></simple-badge>
<simple-badge dot><view>圆点</view></simple-badge>
simple-tag 标签
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
text |
String | '' |
标签文字(也可用插槽) |
type |
String | default |
primary / success / warning / error / info / default |
size |
String | default |
small / default / large |
closable |
Boolean | false |
是否可关闭 |
round |
Boolean | false |
圆角(胶囊形) |
plain |
Boolean | false |
朴素样式(浅底深字) |
color |
String | '' |
自定义文字颜色 |
bgColor |
String | '' |
自定义背景色(plain 下不生效) |
事件:click、close 插槽:默认
<simple-tag text="主要" type="primary" />
<simple-tag text="朴素" type="primary" plain />
<simple-tag text="圆角" type="success" round />
<simple-tag text="可关闭" type="warning" closable @close="onClose" />
simple-progress 进度条
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
percent |
String / Number | 0 |
进度百分比,自动收敛到 0~100 |
strokeWidth |
String / Number | 0 |
进度条粗细(rpx),不传用主题变量 |
color |
String | '' |
进度条颜色,优先级高于 status |
status |
String | '' |
状态色:success / warning / error |
showText |
Boolean | true |
是否显示右侧百分比 |
trackColor |
String | '' |
轨道背景色 |
插槽:默认(替换百分比文字)
<simple-progress :percent="30" />
<simple-progress :percent="60" status="success" />
<simple-progress :percent="80" status="warning" :stroke-width="20" />
<simple-progress :percent="95" color="#8e44ad" />
simple-empty 空状态
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
description |
String | 暂无数据 |
描述文字 |
image |
String | '' |
自定义图片地址 |
imageSize |
String / Number | 160 |
图片尺寸(rpx) |
color |
String | '' |
描述文字颜色 |
customStyle |
String | '' |
自定义容器样式 |
插槽:默认(底部操作区)、image(替换占位图)
<simple-empty />
<simple-empty description="还没有添加任何商品">
<simple-button text="去添加" type="primary" size="small" />
</simple-empty>
默认占位图用纯 CSS 绘制,不依赖图片资源,因此不会增加包体积。
simple-loading 加载中
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
type |
String | spinner |
spinner 弧线 / circle 圆环 / dots 三点 |
size |
String / Number | 48 |
尺寸(rpx) |
color |
String | '' |
颜色 |
text |
String | '' |
文案(也可用插槽) |
textColor |
String | '' |
文案颜色 |
layout |
String | row |
row 横排 / column 竖排 |
插槽:默认(替换文案)
<simple-loading type="spinner" :size="40" />
<simple-loading type="circle" :size="40" color="#19be6b" />
<simple-loading type="dots" :size="40" color="#ff9900" />
<simple-loading type="spinner" text="加载中..." layout="column" />
simple-skeleton 骨架屏
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
loading |
Boolean | true |
为 true 显示骨架,false 渲染默认插槽 |
rows |
String / Number | 3 |
正文行数 |
animated |
Boolean | true |
是否显示呼吸动画 |
avatar |
Boolean | false |
是否显示头像占位 |
title |
Boolean | true |
是否显示标题行 |
avatarSize |
String / Number | 96 |
头像占位尺寸(rpx) |
插槽:默认(loading 为 false 时渲染)
<simple-skeleton :loading="loading" :rows="3" avatar>
<view>真实内容</view>
</simple-skeleton>
动画用透明度呼吸而非渐变位移——小程序对
background-position动画支持不稳定。
simple-divider 分割线
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
vertical |
Boolean | false |
是否为垂直分割线 |
text |
String | '' |
中间文字(也可用插槽) |
position |
String | center |
文字位置:left / center / right |
color |
String | '' |
线条颜色 |
dashed |
Boolean | false |
是否虚线 |
textColor |
String | '' |
文字颜色 |
height |
String / Number | 32 |
垂直分割线高度(rpx) |
<simple-divider />
<simple-divider text="居中文字" />
<simple-divider text="靠左" position="left" />
<simple-divider text="虚线" dashed />
<simple-divider vertical />
simple-countdown 倒计时
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
time |
String / Number | 0 |
倒计时时长(毫秒) |
format |
String | HH:mm:ss |
展示格式,支持 DD / HH / mm / ss |
autoStart |
Boolean | true |
是否自动开始 |
autoReset |
Boolean | false |
归零后是否自动重新开始 |
color |
String | '' |
文字颜色 |
customStyle |
String | '' |
自定义容器样式 |
事件:change、finish、start、pause
插槽:默认,作用域参数 { display, remain }
方法:start()、pause()、reset()
<simple-countdown :time="90000" />
<simple-countdown :time="90000" format="DD天HH时mm分ss秒" />
<simple-countdown ref="cd" :time="90000" :auto-start="false" @finish="onFinish" />
<!-- 通过 ref 控制 -->
this.$refs.cd.start()
this.$refs.cd.pause()
this.$refs.cd.reset()
simple-input 输入框
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
String / Number | '' |
绑定值 |
placeholder |
String | 请输入 |
占位文案 |
type |
String | text |
text / number / digit / password / idcard |
label |
String | '' |
左侧标签文案 |
labelWidth |
String / Number | 0 |
左侧标签宽度(rpx) |
disabled / readonly |
Boolean | false |
禁用 / 只读 |
clearable |
Boolean | false |
是否可清空 |
maxlength |
String / Number | 140 |
最大长度 |
showWordLimit |
Boolean | false |
显示字数统计 |
prefixIcon / suffixIcon |
String | '' |
前后置图标名 |
border |
String | surround |
surround 全边框 / bottom 下边框 / none 无边框 |
error / required |
Boolean | false |
错误态 / 必填标记 |
align |
String | left |
文字对齐 |
事件:update:modelValue、input、change、focus、blur、clear、confirm
插槽:prefix、suffix
<simple-input v-model="name" label="姓名" clearable placeholder="请输入姓名" />
<simple-input v-model="pwd" type="password" prefix-icon="user" />
<simple-input v-model="txt" :maxlength="50" show-word-limit />
simple-textarea 文本域
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
String / Number | '' |
绑定值 |
placeholder |
String | 请输入内容 |
占位文案 |
disabled |
Boolean | false |
禁用 |
maxlength |
String / Number | 200 |
最大长度 |
autoHeight |
Boolean | false |
自动增高(false 时用 height 固定高度) |
height |
String / Number | 200 |
固定高度(rpx) |
showWordLimit |
Boolean | true |
显示字数统计 |
border |
String | surround |
同 simple-input |
error |
Boolean | false |
错误态 |
事件:update:modelValue、input、change、focus、blur
<simple-textarea v-model="desc" :maxlength="200" auto-height placeholder="请输入描述" />
simple-inputnumber 数字输入框
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
String / Number | 0 |
绑定值 |
min / max |
Number | -Infinity / Infinity |
取值范围 |
step |
String / Number | 1 |
步长 |
precision |
String / Number | -1 |
小数位数,-1 不限制 |
disabled / readonly |
Boolean | false |
禁用 / 只读 |
showButton |
Boolean | true |
是否显示两侧按钮 |
事件:update:modelValue、change、plus、minus
<simple-inputnumber v-model="count" :min="1" :max="99" />
<simple-inputnumber v-model="price" :step="0.1" :precision="2" />
输入过程中不立即收敛,失焦时才做范围收敛与精度处理,避免打断输入。 内部用
toFixed处理浮点误差(如0.1 + 0.2)。
simple-search 搜索框
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
String / Number | '' |
绑定值 |
placeholder |
String | 请输入关键字 |
占位文案 |
disabled |
Boolean | false |
禁用 |
clearable |
Boolean | true |
是否可清空 |
shape |
String | round |
round 圆角 / square 方形 |
showAction |
Boolean | false |
显示右侧操作按钮 |
actionText |
String | 搜索 |
右侧按钮文字 |
focused |
Boolean | false |
自动聚焦 |
事件:update:modelValue、input、change、search、clear、focus、blur、action
插槽:action
<simple-search v-model="kw" @search="onSearch" />
<simple-search v-model="kw" show-action action-text="搜索" @search="onSearch" />
simple-radio-group / simple-radio 单选框
RadioGroup
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
String / Number / Boolean | '' |
当前选中值 |
direction |
String | row |
row 横向 / column 纵向 |
disabled |
Boolean | false |
禁用整组 |
shape |
String | circle |
circle / square |
activeColor |
String | '' |
选中颜色 |
iconSize |
String / Number | 0 |
图标尺寸(rpx) |
Radio
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
label |
String / Number / Boolean | '' |
该选项的值(组内唯一) |
text |
String | '' |
展示文字(也可用默认插槽) |
disabled |
Boolean | false |
禁用该项 |
shape |
String | '' |
覆盖组的形状设置 |
事件:RadioGroup change;Radio change
<simple-radio-group v-model="gender" direction="row">
<simple-radio label="1" text="男" />
<simple-radio label="2" text="女" />
<simple-radio label="3" text="保密" disabled />
</simple-radio-group>
label是值,显示文字来自text或默认插槽 —— 与 uView 等库的习惯一致。
simple-checkbox-group / simple-checkbox 复选框
CheckboxGroup
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
Array | [] |
选中值数组 |
direction |
String | row |
row / column |
disabled |
Boolean | false |
禁用整组 |
max |
String / Number | 0 |
最大勾选数,0 不限制 |
shape |
String | square |
square / circle |
activeColor |
String | '' |
选中颜色 |
Checkbox
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
label |
String / Number / Boolean | '' |
该选项的值 |
text |
String | '' |
展示文字 |
disabled |
Boolean | false |
禁用该项 |
checked |
Boolean | false |
独立使用时的选中状态 |
事件:CheckboxGroup change、overflow(超出 max 时触发);Checkbox change
<simple-checkbox-group v-model="hobbies" :max="3" @overflow="onOverflow">
<simple-checkbox label="a" text="阅读" />
<simple-checkbox label="b" text="运动" />
<simple-checkbox label="c" text="音乐" />
</simple-checkbox-group>
simple-switch 开关
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
Boolean | false |
绑定值 |
disabled / loading |
Boolean | false |
禁用 / 加载中(均不可点击) |
activeText / inactiveText |
String | '' |
开 / 关状态文字 |
activeColor / inactiveColor |
String | '' |
开 / 关颜色 |
size |
String | default |
small / default / large |
事件:update:modelValue、change
<simple-switch v-model="enabled" />
<simple-switch v-model="enabled" active-text="开" inactive-text="关" active-color="#19be6b" />
simple-slider 滑块
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
Number / Array | 0 |
单滑块传数字;双滑块传 [start, end] |
min / max |
Number | 0 / 100 |
范围 |
step |
Number | 1 |
步长 |
disabled |
Boolean | false |
禁用 |
showValue |
Boolean | false |
显示当前值 |
range |
Boolean | false |
双滑块区间模式 |
activeColor / inactiveColor |
String | '' |
已选 / 轨道颜色 |
事件:update:modelValue、change、drag
<simple-slider v-model="progress" :min="0" :max="100" show-value />
<simple-slider v-model="priceRange" range :min="0" :max="1000" show-value />
触摸热区上下各留 24rpx,把细轨道的可点区域撑到 56rpx。 双滑块拖动时自动判断该拖哪一个,并保证
start <= end。
simple-rate 评分
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
String / Number | 0 |
当前评分 |
max |
String / Number | 5 |
总分(星星数) |
disabled |
Boolean | false |
不可点击 |
allowHalf |
Boolean | false |
允许半星 |
color / voidColor |
String | '' |
选中 / 未选中颜色 |
size |
String / Number | 0 |
星星尺寸(rpx) |
showText |
Boolean | false |
右侧显示分值 |
事件:update:modelValue、change
<simple-rate v-model="score" />
<simple-rate v-model="score" allow-half show-text />
<simple-rate v-model="score" :max="10" size="56" color="#fa3534" />
半星通过把每颗星拆成左右两个触摸区实现,不依赖坐标计算(更可靠)。 再次点击同一分值会清零。
simple-upload 文件上传
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
Array | [] |
文件列表 [{ url, name, status, progress }] |
action |
String | '' |
上传地址;不传则只保存本地临时路径 |
name |
String | file |
上传字段名 |
formData / header |
Object | {} |
附加参数 / 请求头 |
multiple |
Boolean | false |
是否多选 |
maxCount |
String / Number | 9 |
最大文件数,0 不限制 |
size |
String / Number | 160 |
缩略图尺寸(rpx) |
disabled |
Boolean | false |
禁用 |
preview |
Boolean | true |
点击是否预览 |
tip |
String | '' |
添加按钮下的提示文字 |
showCount |
Boolean | false |
显示数量统计 |
事件:update:modelValue、change、success、fail、remove、preview
插槽:默认(替换添加按钮)、file(自定义文件项,作用域 { file, index })
<simple-upload v-model="files" action="https://example.com/upload" :max-count="9" />
<!-- 只存本地路径,不上传 -->
<simple-upload v-model="files" :max-count="3" tip="上传凭证" />
simple-form 表单
Form
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
model |
Object | {} |
表单数据对象 |
rules |
Object | {} |
校验规则 { 字段名: [规则] } |
labelWidth |
String / Number | 0 |
标签宽度(rpx) |
labelPosition |
String | left |
left 左侧 / top 上方 |
Form 事件:validate(全部通过)、validateFail(返回错误列表)
Form 方法:validate()、validateField(prop)、clearValidate()、resetFields()
校验规则支持
| 规则 | 说明 |
|---|---|
required |
必填(空字符串 / null / 空数组均视为空) |
min / max |
数字比大小,字符串比长度 |
pattern |
正则,可传 RegExp 或字符串 |
validator |
自定义校验,支持返回 false、错误信息字符串、或 Promise |
message |
错误提示文案 |
<simple-form :model="form" :rules="rules" label-width="140">
<simple-form-item label="用户名" prop="name">
<simple-input v-model="form.name" placeholder="请输入用户名" />
</simple-form-item>
<simple-form-item label="手机号" prop="phone">
<simple-input v-model="form.phone" />
</simple-form-item>
</simple-form>
<script>
export default {
data() {
return {
form: { name: '', phone: '' },
rules: {
name: [
{ required: true, message: '请输入用户名' },
{ min: 2, max: 10, message: '长度 2~10 个字符' }
],
phone: [
{ required: true, message: '请输入手机号' },
{ pattern: '^1[3-9]\\d{9}$', message: '手机号格式不正确' }
]
}
}
},
methods: {
async onSubmit() {
const ok = await this.$refs.form.validate()
if (!ok) return
// 校验通过,提交
}
}
}
</script>
- 值变化时自动清除该字段的错误提示,用户改正后不会一直显示红字
resetFields()会恢复到字段注册时的初始值(数组 / 对象做了浅拷贝)- 多字段校验并行执行,提升长表单的响应速度
simple-form-item 表单项
配合 simple-form 使用,负责单个字段的标签、内容与错误提示。
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
label |
String | '' |
标签文字 |
prop |
String | '' |
对应 form.model 的字段名 |
required |
Boolean | false |
显示必填标记(不传则按 rules 自动判断) |
errorMessage |
String | '' |
外部指定错误信息,优先级高于内部校验 |
markerSide |
String | before |
必填标记位置:before / after |
labelWidth |
String / Number | 0 |
标签宽度(rpx),覆盖 Form 的设置 |
labelPosition |
String | '' |
标签位置,覆盖 Form 的设置 |
插槽:label(自定义标签)、默认(内容区,作用域 { value, error })、error(自定义错误提示)
<simple-form-item label="用户名" prop="name">
<simple-input v-model="form.name" placeholder="请输入用户名" />
</simple-form-item>
<!-- 自定义标签与错误提示 -->
<simple-form-item prop="phone">
<template #label>
<text class="my-label">手机号</text>
</template>
<simple-input v-model="form.phone" />
<template #error="{ message }">
<text class="my-error">! {{ message }}</text>
</template>
</simple-form-item>
标签显示条件:有
label、有label插槽、或该字段规则里有required。 想完全不显示标签栏,三个条件都不满足即可。
simple-select 选择器
功能完善的下拉选择器:单选 / 多选、底部弹层 / 顶部弹层 / 下拉面板、默认选中、文字对齐、选项插槽、确认前拦截、选项搜索。
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue |
String / Number / Array | undefined |
绑定值,配合 v-model(多选传数组) |
options |
Array | [] |
选项数组 [{ label, value, disabled }] |
mode |
String | popup |
popup 弹层(带确认)/ dropdown 下拉面板(即时生效) |
position |
String | bottom |
bottom 底部 / top 顶部 |
multiple |
Boolean | false |
是否多选 |
defaultValue |
String / Number / Array | undefined |
默认选中值(非受控初始值) |
align |
String | left |
left / center / right |
placeholder |
String | 请选择 |
占位文字 |
title |
String | 请选择 |
弹层标题(popup 模式) |
labelKey |
String | label |
选项文字字段名 |
valueKey |
String | value |
选项值字段名 |
clearable |
Boolean | false |
是否可清空 |
disabled |
Boolean | false |
是否禁用 |
searchable |
Boolean | false |
是否开启选项搜索 |
searchPlaceholder |
String | 搜索 |
搜索框占位文字 |
emptyText |
String | 暂无数据 |
空数据提示 |
color |
String | '' |
选中文字颜色 |
maxHeight |
String / Number | 640 |
列表最大高度(rpx) |
closeOnClickMask |
Boolean | true |
点击遮罩是否关闭 |
beforeChange |
Function | null |
确认前回调,返回 false 可拦截 |
事件 / 插槽
| 名称 | 类型 | 回调参数 / 说明 |
|---|---|---|
update:modelValue |
事件 | value —— v-model 自动处理 |
change |
事件 | (value, item),多选时 item 为数组 |
confirm |
事件 | value —— 点击「确定」提交成功 |
open / close |
事件 | 面板展开 / 关闭 |
clear |
事件 | 点击清空按钮 |
search |
事件 | keyword —— 搜索关键词变化 |
option |
插槽 | { item, index, selected } —— 自定义选项渲染 |
生效时机
| 模式 | 交互 | 何时触发 change |
|---|---|---|
popup(默认) |
点击选项只更新面板内高亮,点「确定」才提交 | 点击「确定」后 |
dropdown |
点击选项立即生效,单选自动收起 | 点击选项后 |
beforeChange在两种模式下都会触发,可作为统一的拦截入口。
用法
<!-- 基础:底部弹层 -->
<simple-select v-model="city" :options="options" placeholder="请选择城市" />
<!-- 顶部弹层 -->
<simple-select v-model="city" :options="options" position="top" title="请选择" />
<!-- 下拉面板 -->
<simple-select v-model="cate" :options="options" mode="dropdown" />
<!-- 默认选中(非受控) -->
<simple-select :options="options" :default-value="'shanghai'" />
<!-- 多选 -->
<simple-select v-model="values" multiple clearable :options="options" />
<!-- 对齐方式 -->
<simple-select v-model="city" :options="options" align="right" />
<!-- 选项可搜索 -->
<simple-select v-model="city" searchable :options="options" @search="onSearch" />
<!-- 确认前拦截 -->
<simple-select v-model="city" :options="options" :before-change="beforeChange" />
<!-- 自定义选项插槽 -->
<simple-select v-model="city" :options="options">
<template #option="{ item, index, selected }">
<view class="my-option">
<text>{{ index + 1 }}. {{ item.label }}</text>
<text v-if="selected">已选</text>
</view>
</template>
</simple-select>
<!-- 自定义字段名 -->
<simple-select v-model="userId" :options="userList" label-key="name" value-key="id" />
选项数据结构
const options = [
{ label: '北京', value: 'beijing' },
{ label: '上海', value: 'shanghai' },
{ label: '广州(禁用)', value: 'guangzhou', disabled: true }
]
label—— 展示文字(可用labelKey自定义字段名)value—— 选中值(可用valueKey自定义字段名),必须唯一,不要用对象disabled—— 可选,为true时该项不可点击
注意事项
value必须唯一且为基本类型(字符串 / 数字),不要传对象,否则选中判断会失效popup模式基于position: fixed全屏定位,若父级使用了transform会导致定位异常- 选择器列表高度由
maxHeight控制,超过后内部滚动 dropdown模式的面板会撑开父级,建议给外层容器留出空间或设置overflow: visible- 多选的值必须传数组,单选建议传基本类型;清空时单选输出
'',多选输出[] popup模式下点击「取消」或遮罩不会回写值,暂存态会被丢弃- 组件目录名与文件名必须一致(
simple-xxx/simple-xxx.vue),否则 easycom 无法识别

收藏人数:
下载插件并导入HBuilderX
下载示例项目ZIP
赞赏(0)
下载 103
赞赏 1
下载 12671651
赞赏 1955
赞赏
京公网安备:11010802035340号