From 87e59853bbd46543a7e15dc84eac5386a87aa6ed Mon Sep 17 00:00:00 2001 From: nanjingcaiyong <2872845261@qq.com> Date: Tue, 17 Nov 2020 21:45:21 +0800 Subject: [PATCH] fix: the button's loading property without delay (#3194) Co-authored-by: caiyong --- components/button/button.tsx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/components/button/button.tsx b/components/button/button.tsx index f93cddd63..545100b11 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -27,22 +27,25 @@ export default defineComponent({ large: 'lg', small: 'sm', }, - sLoading: !!this.loading, + sLoading: false, hasTwoCNChar: false, }; }, watch: { - loading(val, preVal) { - if (preVal && typeof preVal !== 'boolean') { - clearTimeout(this.delayTimeout); - } - if (val && typeof val !== 'boolean' && val.delay) { - this.delayTimeout = setTimeout(() => { + loading: { + handler(val, preVal) { + if (preVal && typeof preVal !== 'boolean') { + clearTimeout(this.delayTimeout); + } + if (val && typeof val !== 'boolean' && val.delay) { + this.delayTimeout = setTimeout(() => { + this.sLoading = !!val; + }, val.delay); + } else { this.sLoading = !!val; - }, val.delay); - } else { - this.sLoading = !!val; - } + } + }, + immediate: true, }, }, mounted() {