配置说明:
| 参数 | 类型 | 必须 | 默认 | 说明 |
|---|---|---|---|---|
| type | string | Y | 固定值:switch | |
| grid | Array | N | [12, 12, 12, 12] | 栅格布局 |
| name | string | Y | 字段名称 | |
| title | string | Y | 标题 | |
| value | string/int | N | 0 | 默认值:0关闭、1开启 |
| tips | string | N | 提示说明 | |
| attrs | array | N | 扩展属性 | |
| attrs[‘lay-text’] | string | N | 定义开关两种状态的文本,如:“开启|关闭” | |
| attrs[‘disabled’] | bool | N | 禁用开关 |
示例代码:
public function demo(){$assign['buildForm']['items'] = [['type' => 'switch','title' => '开关演示','name' => 'status','value' => 1,'attrs' => ['lay-text' => '开启|关闭',],],// 更多表单项.....];return $this->assign($assign)->fetch();}
渲染效果:

