Switch add new prop: beforeChange
This commit is contained in:
parent
485db11ee2
commit
ae2031aea1
2 changed files with 38 additions and 8 deletions
|
@ -59,7 +59,8 @@
|
|||
},
|
||||
falseColor: {
|
||||
type: String
|
||||
}
|
||||
},
|
||||
beforeChange: Function
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
|
@ -96,18 +97,33 @@
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
toggle (event) {
|
||||
event.preventDefault();
|
||||
if (this.disabled || this.loading) {
|
||||
return false;
|
||||
}
|
||||
|
||||
handleToggle () {
|
||||
const checked = this.currentValue === this.trueValue ? this.falseValue : this.trueValue;
|
||||
|
||||
this.currentValue = checked;
|
||||
this.$emit('input', checked);
|
||||
this.$emit('on-change', checked);
|
||||
this.dispatch('FormItem', 'on-form-change', checked);
|
||||
},
|
||||
toggle (event) {
|
||||
event.preventDefault();
|
||||
if (this.disabled || this.loading) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.beforeChange) {
|
||||
return this.handleToggle();
|
||||
}
|
||||
|
||||
const before = this.beforeChange();
|
||||
|
||||
if (before && before.then) {
|
||||
before.then(() => {
|
||||
this.handleToggle();
|
||||
});
|
||||
} else {
|
||||
this.handleToggle();
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue