mirror of
https://github.com/youzan/vant.git
synced 2025-10-19 01:54:48 +00:00
[Improvement] optimize find parent mixin (#781)
This commit is contained in:
@@ -40,44 +40,33 @@ export default create({
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
value(val) {
|
||||
this.$emit('change', val);
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
this.findParentByName('van-checkbox-group');
|
||||
return {};
|
||||
},
|
||||
|
||||
computed: {
|
||||
currentValue: {
|
||||
get() {
|
||||
return this.parentGroup
|
||||
? this.parentGroup.value.indexOf(this.name) !== -1
|
||||
return this.parent
|
||||
? this.parent.value.indexOf(this.name) !== -1
|
||||
: this.value;
|
||||
},
|
||||
|
||||
set(val) {
|
||||
const { parentGroup } = this;
|
||||
if (parentGroup) {
|
||||
const parentValue = this.parentGroup.value.slice();
|
||||
const { parent } = this;
|
||||
if (parent) {
|
||||
const parentValue = this.parent.value.slice();
|
||||
if (val) {
|
||||
if (parentGroup.max && parentValue.length >= parentGroup.max) {
|
||||
if (parent.max && parentValue.length >= parent.max) {
|
||||
return;
|
||||
}
|
||||
/* istanbul ignore else */
|
||||
if (parentValue.indexOf(this.name) === -1) {
|
||||
parentValue.push(this.name);
|
||||
parentGroup.$emit('input', parentValue);
|
||||
parent.$emit('input', parentValue);
|
||||
}
|
||||
} else {
|
||||
const index = parentValue.indexOf(this.name);
|
||||
/* istanbul ignore else */
|
||||
if (index !== -1) {
|
||||
parentValue.splice(index, 1);
|
||||
parentGroup.$emit('input', parentValue);
|
||||
parent.$emit('input', parentValue);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -96,10 +85,20 @@ export default create({
|
||||
},
|
||||
|
||||
isDisabled() {
|
||||
return (this.parentGroup && this.parentGroup.disabled) || this.disabled;
|
||||
return (this.parent && this.parent.disabled) || this.disabled;
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
value(val) {
|
||||
this.$emit('change', val);
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
this.findParent('van-checkbox-group');
|
||||
},
|
||||
|
||||
methods: {
|
||||
onClick(target) {
|
||||
if (!this.isDisabled && !(target === 'label' && this.labelDisabled)) {
|
||||
|
Reference in New Issue
Block a user