From e9d521a8d2c6c37f19d712542bedcb5cd6e4e50c Mon Sep 17 00:00:00 2001 From: landluck Date: Thu, 12 Jan 2023 10:53:05 +0800 Subject: [PATCH] fix(stepper): fix unable update value in async change (#5191) --- packages/common/component.ts | 1 + packages/definitions/index.ts | 2 ++ packages/stepper/index.ts | 14 ++++++++------ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/common/component.ts b/packages/common/component.ts index d1d10154..f0f95b41 100644 --- a/packages/common/component.ts +++ b/packages/common/component.ts @@ -23,6 +23,7 @@ function VantComponent< mapKeys(vantOptions, options, { data: 'data', props: 'properties', + watch: 'observers', mixins: 'behaviors', methods: 'methods', beforeCreate: 'created', diff --git a/packages/definitions/index.ts b/packages/definitions/index.ts index 2c5c0150..75088076 100644 --- a/packages/definitions/index.ts +++ b/packages/definitions/index.ts @@ -24,6 +24,8 @@ export type VantComponentOptions< mixin: string; }; + watch?: Record any>; + methods?: Methods; // lifetimes diff --git a/packages/stepper/index.ts b/packages/stepper/index.ts index c25bf554..74b9bf33 100644 --- a/packages/stepper/index.ts +++ b/packages/stepper/index.ts @@ -22,7 +22,6 @@ VantComponent({ props: { value: { type: null, - observer: 'observeValue', }, integer: { type: Boolean, @@ -74,6 +73,12 @@ VantComponent({ currentValue: '', }, + watch: { + value() { + this.observeValue(); + }, + }, + created() { this.setData({ currentValue: this.format(this.data.value), @@ -82,11 +87,8 @@ VantComponent({ methods: { observeValue() { - const { value, currentValue } = this.data; - - if (!equal(value, currentValue)) { - this.setData({ currentValue: this.format(value) }); - } + const { value } = this.data; + this.setData({ currentValue: this.format(value) }); }, check() {