diff --git a/src/datetime-picker/index.js b/src/datetime-picker/index.js index 5785c0e85..5d278e36f 100644 --- a/src/datetime-picker/index.js +++ b/src/datetime-picker/index.js @@ -13,7 +13,7 @@ export default createComponent({ methods: { // @exposed-api getPicker() { - return this.$refs.root.getPicker(); + return this.$refs.root.getProxiedPicker(); }, }, diff --git a/src/datetime-picker/shared.js b/src/datetime-picker/shared.js index a59cdbbac..8f301cbe1 100644 --- a/src/datetime-picker/shared.js +++ b/src/datetime-picker/shared.js @@ -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); },