diff --git a/packages/uni-components/src/vue/image/index.tsx b/packages/uni-components/src/vue/image/index.tsx index aad28a85d91137e9b3b232dc58621429e738406e..45f94a76b557e1078cb35b7417857fc04e8d536d 100644 --- a/packages/uni-components/src/vue/image/index.tsx +++ b/packages/uni-components/src/vue/image/index.tsx @@ -35,10 +35,15 @@ const props = { type ImageProps = ExtractPropTypes type ImageState = ReturnType type FixSize = ReturnType['fixSize'] +type FixMode = [ + 'offsetWidth' | 'offsetHeight', + 'height' | 'width', + (value: number, ratio: number) => number +] -const FIX_MODES = { - widthFix: ['offsetWidth', 'height'], - heightFix: ['offsetHeight', 'width'], +const FIX_MODES: Record = { + widthFix: ['offsetWidth', 'height', (value, ratio) => value / ratio], + heightFix: ['offsetHeight', 'width', (value, ratio) => value * ratio], } const IMAGE_MODES = { aspectFit: ['center center', 'contain'], @@ -209,10 +214,9 @@ function useImageSize( return } const rootEl = rootRef.value! - const value = rootEl[names[0] as 'offsetWidth' | 'offsetHeight'] + const value = rootEl[names[0]] if (value) { - rootEl.style[names[1] as 'height' | 'width'] = - fixNumber(value / ratio) + 'px' + rootEl.style[names[1]] = fixNumber(names[2](value, ratio)) + 'px' } if (__PLATFORM__ === 'app') { window.dispatchEvent(new CustomEvent('updateview'))