fix: 修复avatar组件在部分缩放比例下出现页面卡死 #116

修复调整缩放比例,刷新页面,导致无限更新this.scale,出现卡死状况
This commit is contained in:
zhowiny 2021-01-12 11:12:29 +08:00 committed by GitHub
parent 6ee13b133a
commit 91e7f7f7e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,7 +45,8 @@
prefixCls: prefixCls, prefixCls: prefixCls,
scale: 1, scale: 1,
childrenWidth: 0, childrenWidth: 0,
isSlotShow: false isSlotShow: false,
slotTemp: null
}; };
}, },
computed: { computed: {
@ -85,6 +86,11 @@
return style; return style;
} }
}, },
watch: {
size: function (val, oldVal) {
if (val !== oldVal) this.setScale();
},
},
methods: { methods: {
setScale () { setScale () {
this.isSlotShow = !this.src && !this.icon; this.isSlotShow = !this.src && !this.icon;
@ -104,11 +110,17 @@
this.$emit('on-error', e); this.$emit('on-error', e);
} }
}, },
beforeCreate () {
this.slotTemp = this.$slots.default;
},
mounted () { mounted () {
this.setScale(); this.setScale();
}, },
updated () { updated () {
this.setScale(); if (this.$slots.default !== this.slotTemp) {
this.slotTemp = this.$slots.default;
this.setScale();
}
} }
}; };
</script> </script>