diff --git a/packages/uni-components/src/components/image/index.tsx b/packages/uni-components/src/components/image/index.tsx index f40ddd36fa4bf6aa6caf03e0a47bb728c9d9df8c..078314612ef1ab6f8914bbd804f216c8fa834388 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 186621c7d1fd9583630a4e2f3ba9d855f0e9ef34..7c1d0480735b49ce11955875f362261101975774 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) {