From 4b20374bf1875db7fff2c1452fc41cdc57ba41b1 Mon Sep 17 00:00:00 2001 From: baiyaaaaa Date: Mon, 19 Dec 2016 01:10:49 +0800 Subject: [PATCH] support use checkbox without transport value --- packages/checkbox/src/checkbox.vue | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/checkbox/src/checkbox.vue b/packages/checkbox/src/checkbox.vue index 956eb5c43..069c826b9 100644 --- a/packages/checkbox/src/checkbox.vue +++ b/packages/checkbox/src/checkbox.vue @@ -49,17 +49,27 @@ componentName: 'ElCheckbox', + data() { + return { + selfModel: false + }; + }, + computed: { model: { get() { - return this.isGroup ? this.store : this.value; + return this.isGroup + ? this.store : this.value !== undefined + ? this.value : this.selfModel; }, set(val) { if (this.isGroup) { this.dispatch('ElCheckboxGroup', 'input', [val]); - } else { + } else if (this.value !== undefined) { this.$emit('input', val); + } else { + this.selfModel = val; } } }, @@ -105,8 +115,11 @@ methods: { addToStore() { - if (Array.isArray(this.model)) { - this.model.indexOf(this.label) === -1 && this.model.push(this.label); + if ( + Array.isArray(this.model) && + this.model.indexOf(this.label) === -1 + ) { + this.model.push(this.label); } else { this.model = this.trueLabel || true; }