From cbe03a12b2f4a79311b6e7a95d13811ae3a41a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Wed, 1 Mar 2017 17:58:40 +0800 Subject: [PATCH] support Checkbox support Checkbox --- CHANGE.md | 4 + README.md | 2 +- src/components/checkbox/checkbox-group.vue | 23 ++++-- src/components/checkbox/checkbox.vue | 37 +++++---- src/components/radio/radio-group.vue | 2 +- src/components/radio/radio.vue | 1 + src/index.js | 6 +- test/app.vue | 1 + test/main.js | 4 + test/routers/checkbox.vue | 95 ++++++++++++++++++++++ 10 files changed, 146 insertions(+), 29 deletions(-) create mode 100644 test/routers/checkbox.vue diff --git a/CHANGE.md b/CHANGE.md index 3e89c5fa..ffeca998 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -4,3 +4,7 @@ 使用 v-model ### Radio value 改为了 label,使用 v-model,废弃 checked +### Checkbox +使用 v-model +### CheckboxGroup +value 改为了 label,使用 v-model,废弃 checked \ No newline at end of file diff --git a/README.md b/README.md index 81fe8fca..3244bf38 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ - [x] Icon - [x] Input - [x] Radio -- [ ] Checkbox +- [x] Checkbox - [ ] Switch - [ ] Table - [ ] Select diff --git a/src/components/checkbox/checkbox-group.vue b/src/components/checkbox/checkbox-group.vue index 74f99002..c6e9942a 100644 --- a/src/components/checkbox/checkbox-group.vue +++ b/src/components/checkbox/checkbox-group.vue @@ -9,42 +9,49 @@ export default { name: 'checkboxGroup', props: { - model: { + value: { type: Array, default () { return []; } } }, + data () { + return { + currentValue: this.value + }; + }, computed: { classes () { return `${prefixCls}`; } }, - compiled () { + mounted () { this.updateModel(true); }, methods: { updateModel (update) { - const model = this.model; + const value = this.value; this.$children.forEach((child) => { - child.model = model; + child.model = value; if (update) { - child.selected = model.indexOf(child.value) >= 0; + child.currentValue = value.indexOf(child.label) >= 0; child.group = true; } }); }, change (data) { - this.model = data; + this.currentValue = data; + this.$emit('input', data); this.$emit('on-change', data); - this.$dispatch('on-form-change', data); + // todo 事件 +// this.$dispatch('on-form-change', data); } }, watch: { - model () { + value () { this.updateModel(true); } } diff --git a/src/components/checkbox/checkbox.vue b/src/components/checkbox/checkbox.vue index 90d99b72..bc652294 100644 --- a/src/components/checkbox/checkbox.vue +++ b/src/components/checkbox/checkbox.vue @@ -7,7 +7,7 @@ type="checkbox" :class="inputClasses" :disabled="disabled" - :value="value" + :value="label" v-model="model" @change="change"> - {{ value }} + {{ label }}