diff --git a/packages/uni-app-plus/dist/uni-app-view.umd.js b/packages/uni-app-plus/dist/uni-app-view.umd.js index ec56143982c2dbc4676301134275c47288c61258..383821ad8fdf33ac3e8a66be826037de908fcf32 100644 --- a/packages/uni-app-plus/dist/uni-app-view.umd.js +++ b/packages/uni-app-plus/dist/uni-app-view.umd.js @@ -6152,12 +6152,9 @@ }); watch(() => extend({}, size2), (value) => emit2("resize", value)); return () => { - const { - width, - height - } = rootRef.value.getBoundingClientRect(); - size2.width = width; - size2.height = height; + const rootEl = rootRef.value; + size2.width = rootEl.offsetWidth; + size2.height = rootEl.offsetHeight; reset2(); }; } @@ -6278,8 +6275,8 @@ } }; const FIX_MODES = { - widthFix: ["width", "height"], - heightFix: ["height", "width"] + widthFix: ["offsetWidth", "height"], + heightFix: ["offsetHeight", "width"] }; const IMAGE_MODES = { aspectFit: ["center center", "contain"], @@ -6449,8 +6446,7 @@ return; } const rootEl = rootRef.value; - const rect = rootEl.getBoundingClientRect(); - const value = rect[names[0]]; + const value = rootEl[names[0]]; if (value) { rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; } diff --git a/packages/uni-components/src/components/image/index.tsx b/packages/uni-components/src/components/image/index.tsx index bda17927d9ce0f227a3d5213e5348e8eaddc5893..b7491ac52008c5250a665c0b95bfb7700c7021ee 100644 --- a/packages/uni-components/src/components/image/index.tsx +++ b/packages/uni-components/src/components/image/index.tsx @@ -37,8 +37,8 @@ type ImageState = ReturnType type FixSize = ReturnType['fixSize'] const FIX_MODES = { - widthFix: ['width', 'height'], - heightFix: ['height', 'width'], + widthFix: ['offsetWidth', 'height'], + heightFix: ['offsetHeight', 'width'], } const IMAGE_MODES = { aspectFit: ['center center', 'contain'], @@ -76,6 +76,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
{imgSrc ? : } {FIX_MODES[mode as keyof typeof FIX_MODES] ? ( + // @ts-ignore ) : ( @@ -209,8 +210,7 @@ function useImageSize( return } const rootEl = rootRef.value! - const rect = rootEl.getBoundingClientRect() - const value = rect[names[0] as keyof DOMRect] as number + const value = rootEl[names[0] as 'offsetWidth' | 'offsetHeight'] if (value) { rootEl.style[names[1] as 'height' | 'width'] = fixNumber(value / ratio) + 'px' diff --git a/packages/uni-components/src/components/resize-sensor/index.tsx b/packages/uni-components/src/components/resize-sensor/index.tsx index 779c4174b03a85f86a4e888586aad2060cbababd..ceb880c2a32ead740a7d1e9a6d4630467716c3f1 100644 --- a/packages/uni-components/src/components/resize-sensor/index.tsx +++ b/packages/uni-components/src/components/resize-sensor/index.tsx @@ -49,9 +49,9 @@ function useResizeSensorUpdate( (value: typeof size) => emit('resize', value) ) return () => { - const { width, height } = rootRef.value!.getBoundingClientRect() - size.width = width - size.height = height + const rootEl = rootRef.value! + size.width = rootEl.offsetWidth + size.height = rootEl.offsetHeight reset() } } diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index f315388f11a7e598bf9698984e89e7826ab725cf..88221dce32c38054180545261c1fc6f5f4df31b0 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -1573,12 +1573,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) { }); vue.watch(() => shared.extend({}, size), (value) => emit2("resize", value)); return () => { - const { - width, - height - } = rootRef.value.getBoundingClientRect(); - size.width = width; - size.height = height; + const rootEl = rootRef.value; + size.width = rootEl.offsetWidth; + size.height = rootEl.offsetHeight; reset(); }; } @@ -2605,8 +2602,8 @@ const props$p = { } }; const FIX_MODES = { - widthFix: ["width", "height"], - heightFix: ["height", "width"] + widthFix: ["offsetWidth", "height"], + heightFix: ["offsetHeight", "width"] }; const IMAGE_MODES = { aspectFit: ["center center", "contain"], @@ -2764,8 +2761,7 @@ function useImageSize(rootRef, props2, state) { return; } const rootEl = rootRef.value; - const rect = rootEl.getBoundingClientRect(); - const value = rect[names[0]]; + const value = rootEl[names[0]]; if (value) { rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; } diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index fb02b6c9dc3d2df2a6e55744f079d5a0a90ac7bb..40edf07707bf43f185095b16672ac6172385e6c9 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -5780,12 +5780,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) { }); watch(() => extend({}, size), (value) => emit2("resize", value)); return () => { - const { - width, - height - } = rootRef.value.getBoundingClientRect(); - size.width = width; - size.height = height; + const rootEl = rootRef.value; + size.width = rootEl.offsetWidth; + size.height = rootEl.offsetHeight; reset(); }; } @@ -7539,8 +7536,8 @@ const props$w = { } }; const FIX_MODES = { - widthFix: ["width", "height"], - heightFix: ["height", "width"] + widthFix: ["offsetWidth", "height"], + heightFix: ["offsetHeight", "width"] }; const IMAGE_MODES = { aspectFit: ["center center", "contain"], @@ -7710,8 +7707,7 @@ function useImageSize(rootRef, props2, state2) { return; } const rootEl = rootRef.value; - const rect = rootEl.getBoundingClientRect(); - const value = rect[names[0]]; + const value = rootEl[names[0]]; if (value) { rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; }