Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
墝
unidocs-zh
提交
c1f5d265
U
unidocs-zh
项目概览
墝
/
unidocs-zh
与 Fork 源项目一致
Fork自
DCloud / unidocs-zh
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c1f5d265
编写于
9月 21, 2022
作者:
墝
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update checkbox.md
上级
65bf2530
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
142 addition
and
142 deletion
+142
-142
docs/component/checkbox.md
docs/component/checkbox.md
+142
-142
未找到文件。
docs/component/checkbox.md
浏览文件 @
c1f5d265
#### checkbox-group
多项选择器,内部由多个 checkbox 组成。
**属性说明**
|属性名|类型|默认值|说明|
|:-|:-|:-|:-|
|@change|EventHandle||
``<checkbox-group>``
中选中项发生改变是触发 change 事件,detail = {value:[选中的checkbox的value的数组]}|
#### checkbox
多选项目。
**属性说明**
|属性名|类型|默认值|说明|
|:-|:-|:-|:-|
|value|String||
``<checkbox>``
标识,选中时触发
``<checkbox-group>``
的 change 事件,并携带
``<checkbox>``
的 value。|
|disabled|Boolean|false|是否禁用|
|checked|Boolean|false|当前是否选中,可用来设置默认选中
|
|color|Color||checkbox的颜色,同css的color|
**示例**
[
查看演示
](
https://hellouniapp.dcloud.net.cn/pages/component/checkbox/checkbox
)
以下示例代码,来自于
[
hello uni-app项目
](
https://github.com/dcloudio/hello-uniapp
)
,推荐使用HBuilderX,新建uni-app项目,选择hello uni-app模板,可直接体验完整示例。
::: preview https://hellouniapp.dcloud.net.cn/pages/component/checkbox/checkbox
#### checkbox-group
多项选择器,内部由多个 checkbox 组成。
**属性说明**
|属性名|类型|默认值|说明|
|:-|:-|:-|:-|
|@change|EventHandle||
``<checkbox-group>``
中选中项发生改变是触发 change 事件,detail = {value:[选中的checkbox的value的数组]}|
#### checkbox
多选项目。
**属性说明**
|属性名|类型|默认值|说明|
|:-|:-|:-|:-|
|value|String||
``<checkbox>``
标识,选中时触发
``<checkbox-group>``
的 change 事件,并携带
``<checkbox>``
的 value。|
|disabled|Boolean|false|是否禁用|
|checked|Boolean|false|当前是否选中,可用来设置默认选中
,这个地方在json值中不管是false还是TRUE都会选中,只要含了checked字段就会|
|color|Color||checkbox的颜色,同css的color|
**示例**
[
查看演示
](
https://hellouniapp.dcloud.net.cn/pages/component/checkbox/checkbox
)
以下示例代码,来自于
[
hello uni-app项目
](
https://github.com/dcloudio/hello-uniapp
)
,推荐使用HBuilderX,新建uni-app项目,选择hello uni-app模板,可直接体验完整示例。
::: preview https://hellouniapp.dcloud.net.cn/pages/component/checkbox/checkbox
> Template
```
vue
<!-- 本示例未包含完整css,获取外链css请参考上文,在hello uni-app项目中查看 -->
<
template
>
<view>
<view
class=
"uni-padding-wrap uni-common-mt"
>
<view
class=
"uni-title uni-common-mt"
>
默认样式
</view>
<view>
<checkbox-group>
<label>
<checkbox
value=
"cb"
checked=
"true"
/>
选中
</label>
<label>
<checkbox
value=
"cb"
/>
未选中
</label>
</checkbox-group>
</view>
<view
class=
"uni-title uni-common-mt"
>
不同颜色和尺寸的checkbox
</view>
<view>
<checkbox-group>
<label>
<checkbox
value=
"cb"
checked=
"true"
color=
"#FFCC33"
style=
"transform:scale(0.7)"
/>
选中
</label>
<label>
<checkbox
value=
"cb"
color=
"#FFCC33"
style=
"transform:scale(0.7)"
/>
未选中
</label>
</checkbox-group>
</view>
</view>
<view
class=
"uni-padding-wrap"
>
<view
class=
"uni-title uni-common-mt"
>
推荐展示样式
<text>
\n使用 uni-list 布局
</text>
</view>
</view>
<view
class=
"uni-list"
>
<checkbox-group
@
change=
"checkboxChange"
>
<label
class=
"uni-list-cell uni-list-cell-pd"
v-for=
"item in items"
:key=
"item.value"
>
<view>
<checkbox
:value=
"item.value"
:checked=
"item.checked"
/>
</view>
<view>
{{
item
.
name
}}
</view>
</label>
</checkbox-group>
</view>
</view>
</
template
>
```
vue
<!-- 本示例未包含完整css,获取外链css请参考上文,在hello uni-app项目中查看 -->
<
template
>
<view>
<view
class=
"uni-padding-wrap uni-common-mt"
>
<view
class=
"uni-title uni-common-mt"
>
默认样式
</view>
<view>
<checkbox-group>
<label>
<checkbox
value=
"cb"
checked=
"true"
/>
选中
</label>
<label>
<checkbox
value=
"cb"
/>
未选中
</label>
</checkbox-group>
</view>
<view
class=
"uni-title uni-common-mt"
>
不同颜色和尺寸的checkbox
</view>
<view>
<checkbox-group>
<label>
<checkbox
value=
"cb"
checked=
"true"
color=
"#FFCC33"
style=
"transform:scale(0.7)"
/>
选中
</label>
<label>
<checkbox
value=
"cb"
color=
"#FFCC33"
style=
"transform:scale(0.7)"
/>
未选中
</label>
</checkbox-group>
</view>
</view>
<view
class=
"uni-padding-wrap"
>
<view
class=
"uni-title uni-common-mt"
>
推荐展示样式
<text>
\n使用 uni-list 布局
</text>
</view>
</view>
<view
class=
"uni-list"
>
<checkbox-group
@
change=
"checkboxChange"
>
<label
class=
"uni-list-cell uni-list-cell-pd"
v-for=
"item in items"
:key=
"item.value"
>
<view>
<checkbox
:value=
"item.value"
:checked=
"item.checked"
/>
</view>
<view>
{{
item
.
name
}}
</view>
</label>
</checkbox-group>
</view>
</view>
</
template
>
```
> Script
```
vue
<
script
>
export
default
{
data
()
{
return
{
title
:
'
checkbox 复选框
'
,
items
:
[{
value
:
'
USA
'
,
name
:
'
美国
'
},
{
value
:
'
CHN
'
,
name
:
'
中国
'
,
checked
:
'
true
'
},
{
value
:
'
BRA
'
,
name
:
'
巴西
'
},
{
value
:
'
JPN
'
,
name
:
'
日本
'
},
{
value
:
'
ENG
'
,
name
:
'
英国
'
},
{
value
:
'
FRA
'
,
name
:
'
法国
'
}
]
}
},
methods
:
{
checkboxChange
:
function
(
e
)
{
var
items
=
this
.
items
,
values
=
e
.
detail
.
value
;
for
(
var
i
=
0
,
lenI
=
items
.
length
;
i
<
lenI
;
++
i
)
{
const
item
=
items
[
i
]
if
(
values
.
includes
(
item
.
value
)){
this
.
$set
(
item
,
'
checked
'
,
true
)
}
else
{
this
.
$set
(
item
,
'
checked
'
,
false
)
}
}
}
}
}
</
script
>
```
> Style
```
vue
<
style
>
.uni-list-cell
{
justify-content
:
flex-start
}
</
style
>
```
:::
**注意**
-
checkbox的默认颜色,在不同平台不一样。微信小程序、360小程序是绿色的,字节跳动小程序为红色,其他平台是蓝色的。更改颜色使用color属性。
-
如需调节checkbox大小,可通过css的scale方法调节,如缩小到70%
`style="transform:scale(0.7)"`
**扩展**
-
uni-ui提供了增强的uni-data-checkbox组件,基于
[
datacom规范
](
/component/datacom
)
,只需传入data数据,即可自动生成一组复选框,使用方式更简洁,并且支持
[
uni-forms
](
https://ext.dcloud.net.cn/plugin?id=2773
)
的表单验证。uni-data-checkbox组件详见
[
https://ext.dcloud.net.cn/plugin?id=3456
](
https://ext.dcloud.net.cn/plugin?id=3456
)
```
vue
<
script
>
export
default
{
data
()
{
return
{
title
:
'
checkbox 复选框
'
,
items
:
[{
value
:
'
USA
'
,
name
:
'
美国
'
},
{
value
:
'
CHN
'
,
name
:
'
中国
'
,
checked
:
'
true
'
},
{
value
:
'
BRA
'
,
name
:
'
巴西
'
},
{
value
:
'
JPN
'
,
name
:
'
日本
'
},
{
value
:
'
ENG
'
,
name
:
'
英国
'
},
{
value
:
'
FRA
'
,
name
:
'
法国
'
}
]
}
},
methods
:
{
checkboxChange
:
function
(
e
)
{
var
items
=
this
.
items
,
values
=
e
.
detail
.
value
;
for
(
var
i
=
0
,
lenI
=
items
.
length
;
i
<
lenI
;
++
i
)
{
const
item
=
items
[
i
]
if
(
values
.
includes
(
item
.
value
)){
this
.
$set
(
item
,
'
checked
'
,
true
)
}
else
{
this
.
$set
(
item
,
'
checked
'
,
false
)
}
}
}
}
}
</
script
>
```
> Style
```
vue
<
style
>
.uni-list-cell
{
justify-content
:
flex-start
}
</
style
>
```
:::
**注意**
-
checkbox的默认颜色,在不同平台不一样。微信小程序、360小程序是绿色的,字节跳动小程序为红色,其他平台是蓝色的。更改颜色使用color属性。
-
如需调节checkbox大小,可通过css的scale方法调节,如缩小到70%
`style="transform:scale(0.7)"`
**扩展**
-
uni-ui提供了增强的uni-data-checkbox组件,基于
[
datacom规范
](
/component/datacom
)
,只需传入data数据,即可自动生成一组复选框,使用方式更简洁,并且支持
[
uni-forms
](
https://ext.dcloud.net.cn/plugin?id=2773
)
的表单验证。uni-data-checkbox组件详见
[
https://ext.dcloud.net.cn/plugin?id=3456
](
https://ext.dcloud.net.cn/plugin?id=3456
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录