fix(DatetimePicker): should update value after calling picker methods (#10028)

This commit is contained in:
neverland 2021-12-11 10:39:56 +08:00 committed by GitHub
parent 29b1449977
commit 1d4c4df4fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions

View File

@ -13,7 +13,7 @@ export default createComponent({
methods: {
// @exposed-api
getPicker() {
return this.$refs.root.getPicker();
return this.$refs.root.getProxiedPicker();
},
},

View File

@ -60,27 +60,43 @@ export const TimePickerMixin = {
if (!oldVal) {
this.$emit('input', null);
} else {
this.$emit('input', val)
this.$emit('input', val);
}
},
},
mounted() {
this.updateColumnValue();
this.$nextTick(() => {
this.updateInnerValue();
});
},
methods: {
// @exposed-api
getPicker() {
return this.$refs.picker;
},
// https://github.com/youzan/vant/issues/10013
getProxiedPicker() {
const { picker } = this.$refs;
if (picker) {
const proxy = (fn) => (...args) => {
picker[fn](...args);
this.updateInnerValue();
};
return {
...picker,
setValues: proxy('setValues'),
setIndexes: proxy('setIndexes'),
setColumnIndex: proxy('setColumnIndex'),
setColumnValue: proxy('setColumnValue'),
};
}
},
onConfirm() {
this.$emit('input', this.innerValue)
this.$emit('input', this.innerValue);
this.$emit('confirm', this.innerValue);
},