From 0fb61a2edaa44a177fb1bb334149f1a957fdf2c8 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 20 Apr 2021 18:27:36 +0800 Subject: [PATCH] fix: image load --- .../uni-components/src/components/image/index.tsx | 11 +++++++++-- packages/uni-h5/dist/uni-h5.esm.js | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/uni-components/src/components/image/index.tsx b/packages/uni-components/src/components/image/index.tsx index f40ddd36f..078314612 100644 --- a/packages/uni-components/src/components/image/index.tsx +++ b/packages/uni-components/src/components/image/index.tsx @@ -106,7 +106,7 @@ function useImageState(rootRef: Ref, props: ImageProps) { }) const state = reactive({ rootEl: rootRef, - src: computed(() => getRealPath(props.src)), + src: computed(() => (props.src ? getRealPath(props.src) : '')), origWidth: 0, origHeight: 0, origStyle: { width: '', height: '' }, @@ -138,7 +138,11 @@ function useImageLoader( const loadImage = (src: string) => { if (!src) { resetImage() - resetSize() + state.origWidth = 0 + state.origHeight = 0 + state.imgSrc = '' + // 与微信小程序保持一致,保留之前样式 + // resetSize() return } if (!img) { @@ -215,6 +219,9 @@ function useImageSize( rootEl.style[names[1] as 'height' | 'width'] = fixNumber(value / ratio) + 'px' } + if (__PLATFORM__ === 'app') { + window.dispatchEvent(new CustomEvent('updateview')) + } } const resetSize = () => { const { style } = rootRef.value! diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 186621c7d..7c1d04807 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -5908,7 +5908,7 @@ function useImageState(rootRef, props2) { }); const state = reactive({ rootEl: rootRef, - src: computed(() => getRealPath(props2.src)), + src: computed(() => props2.src ? getRealPath(props2.src) : ""), origWidth: 0, origHeight: 0, origStyle: { @@ -5935,7 +5935,9 @@ function useImageLoader(state, { const loadImage = (src) => { if (!src) { resetImage(); - resetSize(); + state.origWidth = 0; + state.origHeight = 0; + state.imgSrc = ""; return; } if (!img) { -- GitLab