[Improvement] optimize find parent mixin (#781)

This commit is contained in:
neverland
2018-03-26 21:20:00 +08:00
committed by GitHub
parent dadf733d71
commit 5497eef5ef
13 changed files with 82 additions and 105 deletions
+10 -17
View File
@@ -36,39 +36,32 @@ export default create({
},
computed: {
isGroup() {
return !!this.findParentByName('van-radio-group');
},
currentValue: {
get() {
return this.isGroup && this.parentGroup
? this.parentGroup.value
: this.value;
return this.parent ? this.parent.value : this.value;
},
set(val) {
if (this.isGroup && this.parentGroup) {
this.parentGroup.$emit('input', val);
} else {
this.$emit('input', val);
}
(this.parent || this).$emit('input', val);
}
},
isDisabled() {
return this.isGroup && this.parentGroup
? this.parentGroup.disabled || this.disabled
return this.parent
? this.parent.disabled || this.disabled
: this.disabled;
}
},
created() {
this.findParent('van-radio-group');
},
methods: {
onClickLabel() {
if (this.isDisabled) {
return;
if (!this.isDisabled) {
this.currentValue = this.name;
}
this.currentValue = this.name;
}
}
});