checkbox component

This commit is contained in:
cookfront
2017-03-01 11:15:15 +08:00
parent 38d6771e72
commit e0be5b962e
14 changed files with 283 additions and 26 deletions
+10 -24
View File
@@ -24,9 +24,13 @@
</template>
<script>
import findParent from 'src/mixins/findParent';
export default {
name: 'zan-radio',
mixins: [findParent],
props: {
disabled: Boolean,
value: {},
@@ -35,17 +39,17 @@ export default {
computed: {
isGroup() {
return !!this.findRadioGroup();
return !!this.findParentByComponentName('zan-radio-group');
},
currentValue: {
get() {
return this.isGroup ? (this.parentGroup && this.parentGroup.value) : this.value;
return this.isGroup && this.parentGroup ? this.parentGroup.value : this.value;
},
set(val) {
if (this.isGroup) {
this.parentGroup && this.parentGroup.$emit('input', val);
if (this.isGroup && this.parentGroup) {
this.parentGroup.$emit('input', val);
} else {
this.$emit('input', val);
}
@@ -53,28 +57,10 @@ export default {
},
isDisabled() {
return this.isGroup
? (this.parentGroup && this.parentGroup.disabled) || this.disabled
return this.isGroup && this.parentGroup
? this.parentGroup.disabled || this.disabled
: this.disabled;
}
},
methods: {
findRadioGroup() {
if (this.parentGroup) return;
let parent = this.$parent;
while (parent) {
if (parent.$options.name === 'zan-radio-group') {
this.parentGroup = parent;
break;
} else {
parent = parent.$parent;
}
}
return this.parentGroup;
}
}
};
</script>