From 91e7f7f7e3c381f0844f730f323930cc8f3f3c5a Mon Sep 17 00:00:00 2001 From: zhowiny Date: Tue, 12 Jan 2021 11:12:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Davatar=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=9C=A8=E9=83=A8=E5=88=86=E7=BC=A9=E6=94=BE=E6=AF=94?= =?UTF-8?q?=E4=BE=8B=E4=B8=8B=E5=87=BA=E7=8E=B0=E9=A1=B5=E9=9D=A2=E5=8D=A1?= =?UTF-8?q?=E6=AD=BB=20#116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复调整缩放比例,刷新页面,导致无限更新this.scale,出现卡死状况 --- src/components/avatar/avatar.vue | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/avatar/avatar.vue b/src/components/avatar/avatar.vue index 91285f14..a40368c6 100644 --- a/src/components/avatar/avatar.vue +++ b/src/components/avatar/avatar.vue @@ -45,7 +45,8 @@ prefixCls: prefixCls, scale: 1, childrenWidth: 0, - isSlotShow: false + isSlotShow: false, + slotTemp: null }; }, computed: { @@ -85,6 +86,11 @@ return style; } }, + watch: { + size: function (val, oldVal) { + if (val !== oldVal) this.setScale(); + }, + }, methods: { setScale () { this.isSlotShow = !this.src && !this.icon; @@ -104,11 +110,17 @@ this.$emit('on-error', e); } }, + beforeCreate () { + this.slotTemp = this.$slots.default; + }, mounted () { this.setScale(); }, updated () { - this.setScale(); + if (this.$slots.default !== this.slotTemp) { + this.slotTemp = this.$slots.default; + this.setScale(); + } } };