From 08bfd3a8a3b9e0add6a07914fcdc85954fc78f0a Mon Sep 17 00:00:00 2001 From: "yugang.cao" Date: Tue, 13 Jul 2021 11:16:09 +0800 Subject: [PATCH] fix: onError add event and objectFit set default value --- src/avatar/src/Avatar.tsx | 19 +++++++++++++------ src/image/src/Image.tsx | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/avatar/src/Avatar.tsx b/src/avatar/src/Avatar.tsx index ab355fee092..054778ff60f 100644 --- a/src/avatar/src/Avatar.tsx +++ b/src/avatar/src/Avatar.tsx @@ -27,14 +27,17 @@ const avatarProps = { default: false }, color: String, - objectFit: String as PropType< - 'fill' | 'contain' | 'cover' | 'none' | 'scale-down' - >, + objectFit: { + type: String as PropType< + 'fill' | 'contain' | 'cover' | 'none' | 'scale-down' + >, + default: 'fill' + }, round: { type: Boolean, default: false }, - onError: Function as PropType<() => void> + onError: Function as PropType<(e: Event) => void> } as const export type AvatarProps = ExtractPublicPropTypes @@ -85,8 +88,12 @@ export default defineComponent({ textRef, selfRef, mergedClsPrefix: mergedClsPrefixRef, + handleError: (e: Event) => { + const { onError } = props + onError?.(e) + }, cssVars: computed(() => { - const { size, round, circle, objectFit = 'fill' } = props + const { size, round, circle, objectFit } = props const { self: { borderRadius, fontSize, color }, common: { cubicBezierEaseInOut } @@ -117,7 +124,7 @@ export default defineComponent({ style={this.cssVars as any} > {!$slots.default && src ? ( - + ) : ( , imgProps: Object as PropType, - objectFit: String as PropType< - 'fill' | 'contain' | 'cover' | 'none' | 'scale-down' - >, + objectFit: { + type: String as PropType< + 'fill' | 'contain' | 'cover' | 'none' | 'scale-down' + >, + default: 'fill' + }, width: [String, Number] as PropType, src: String, showToolbar: { type: Boolean, default: true }, - onError: Function as PropType<() => void> + onError: Function as PropType<(e: Event) => void> } export type ImageProps = ExtractPublicPropTypes @@ -70,8 +73,12 @@ export default defineComponent({ previewInst.setThumbnailEl(imageRef.value) previewInst.toggleShow() }, + handleError: (e: Event) => { + const { onError } = props + onError?.(e) + }, cssVars: computed(() => { - const { objectFit = 'fill' } = props + const { objectFit } = props return { '--object-fit': objectFit } @@ -98,7 +105,7 @@ export default defineComponent({ alt={this.alt ? this.alt : imgProps.alt} aria-label={this.alt ? this.alt : imgProps.alt} onClick={this.handleClick} - onError={this.onError} + onError={this.handleError} /> )