Commit 71699f6b29638b46c041c06ef340a5a96176c18c
1 parent
9a9e103f
optimize Checkbox in single type without slot
optimize Checkbox in single type without slot
Showing
2 changed files
with
9 additions
and
2 deletions
Show diff stats
src/components/checkbox/checkbox.vue
| ... | ... | @@ -18,7 +18,7 @@ |
| 18 | 18 | v-model="checked" |
| 19 | 19 | @change="change"> |
| 20 | 20 | </span> |
| 21 | - <slot><span>{{ value }}</span></slot> | |
| 21 | + <slot v-if="showSlot"><span v-el:slot>{{ value }}</span></slot> | |
| 22 | 22 | </label> |
| 23 | 23 | </template> |
| 24 | 24 | <script> |
| ... | ... | @@ -42,7 +42,8 @@ |
| 42 | 42 | return { |
| 43 | 43 | model: [], |
| 44 | 44 | selected: false, |
| 45 | - group: false | |
| 45 | + group: false, | |
| 46 | + showSlot: true | |
| 46 | 47 | } |
| 47 | 48 | }, |
| 48 | 49 | computed: { |
| ... | ... | @@ -75,6 +76,9 @@ |
| 75 | 76 | ready () { |
| 76 | 77 | if (!this.group) { |
| 77 | 78 | this.updateModel(); |
| 79 | + if (this.$els.slot && this.$els.slot.innerHTML === '') { | |
| 80 | + this.showSlot = false; | |
| 81 | + } | |
| 78 | 82 | } |
| 79 | 83 | }, |
| 80 | 84 | methods: { | ... | ... |
test/routers/radio.vue
| ... | ... | @@ -141,6 +141,8 @@ |
| 141 | 141 | <Breadcrumb-item href="/components/breadcrumb">Components</Breadcrumb-item> |
| 142 | 142 | <Breadcrumb-item>Breadcrumb</Breadcrumb-item> |
| 143 | 143 | </Breadcrumb> |
| 144 | + <br><br> | |
| 145 | + <Checkbox :checked.sync="single"></Checkbox> | |
| 144 | 146 | </template> |
| 145 | 147 | <script> |
| 146 | 148 | import { Radio, Alert, Icon, Collapse, Button, Checkbox, Switch, InputNumber, Breadcrumb, LoadingBar } from 'iview'; |
| ... | ... | @@ -172,6 +174,7 @@ |
| 172 | 174 | }, |
| 173 | 175 | data () { |
| 174 | 176 | return { |
| 177 | + single: false, | |
| 175 | 178 | radio: false, |
| 176 | 179 | radioGroup: '段模', |
| 177 | 180 | activeKey: [1,2], | ... | ... |