Skip to content

Commit 814f1da

Browse files
author
chengaopan
authored
feat: 增加 el-checkbox-button,el-radio-button 支持 (#227)
1 parent e8c33ee commit 814f1da

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

docs/checkbox-group.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export default {
1212
{
1313
id: 'city',
1414
type: 'checkbox-group',
15+
/**
16+
* sytle 属性是为了满足 el-checkbox-button属性而设置,如果不需要使用el-radio-button这可不设置
17+
*/
18+
style: 'button',
1519
label: 'city',
1620
default: ['new york'],
1721
options: [

docs/radio-group.md

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export default {
1313
id: 'city',
1414
type: 'radio-group',
1515
label: 'city',
16+
/**
17+
* sytle 属性是为了满足 el-radio-button属性而设置,如果不需要使用el-radio-button这可不设置
18+
*/
19+
style: 'button',
1620
default: 'new york',
1721
options: [
1822
/**

src/components/render-form-item.vue

+19-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@
4545
:key="optionKey(opt) || index"
4646
v-bind="opt"
4747
/>
48-
<!-- TODO: 支持 el-checkbox-button 变体 -->
48+
<el-checkbox-button
49+
v-else-if="data.type === 'checkbox-group' && data.style === 'button'"
50+
:key="opt.value"
51+
v-bind="opt"
52+
:label="'value' in opt ? opt.value : opt.label"
53+
>
54+
{{ opt.label }}
55+
</el-checkbox-button>
56+
4957
<el-checkbox
50-
v-else-if="data.type === 'checkbox-group'"
58+
v-else-if="data.type === 'checkbox-group' && data.style !== 'button'"
5159
:key="opt.value"
5260
v-bind="opt"
5361
:label="'value' in opt ? opt.value : opt.label"
@@ -56,8 +64,16 @@
5664
</el-checkbox>
5765
<!-- WARNING: radio 用 label 属性来表示 value 的含义 -->
5866
<!-- FYI: radio 的 value 属性可以在没有 radio-group 时用来关联到同一个 v-model -->
67+
<el-radio-button
68+
v-else-if="data.type === 'radio-group' && data.style === 'button'"
69+
:key="opt.label"
70+
v-bind="opt"
71+
:label="'value' in opt ? opt.value : opt.label"
72+
>{{ opt.label }}</el-radio-button
73+
>
74+
5975
<el-radio
60-
v-else-if="data.type === 'radio-group'"
76+
v-else-if="data.type === 'radio-group' && data.style !== 'button'"
6177
:key="opt.label"
6278
v-bind="opt"
6379
:label="'value' in opt ? opt.value : opt.label"

0 commit comments

Comments
 (0)