amis/docs/zh-CN/components/form/switch.md

78 lines
1.5 KiB
Markdown
Raw Normal View History

2020-07-28 10:03:53 +08:00
---
title: Switch 开关
description:
2020-07-28 10:03:53 +08:00
type: 0
group: null
menuName: Switch
icon:
2020-07-28 10:03:53 +08:00
order: 51
---
2020-07-28 10:03:53 +08:00
## 基本用法
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"api": "https://houtai.baidu.com/api/mock2/form/saveForm",
"controls": [
{
"name": "switch",
"type": "switch",
"label": "开关",
"option": "开关说明"
}
]
}
```
## 配置真假值
默认情况:
2020-07-28 10:03:53 +08:00
- 开关打开时表单项值为true
- 开关关闭时表单项值为false
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"debug": true,
"controls": [
{
"name": "switch",
"type": "switch",
"label": "开关"
}
]
}
```
如果你想调整这个值,可以配置`trueValue`和`falseValue`
```schema: scope="body"
2020-07-28 10:03:53 +08:00
{
"type": "form",
"debug": true,
"controls": [
{
"name": "switch",
"type": "switch",
"label": "开关",
"trueValue": 1,
"falseValue": 0
}
]
}
```
调整开关,观察数据域变化,会发现打开后值为`1`,而关闭后为`0`
## 属性表
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
| 属性名 | 类型 | 默认值 | 说明 |
| ---------- | -------- | --------- | -------- |
| option | `string` | | 选项说明 |
| trueValue | `any` | `true` | 标识真值 |
| falseValue | `any` | `"false"` | 标识假值 |