飞翔的熊猫
飞翔的熊猫
  • 发布:2022-06-23 10:53
  • 更新:2022-06-24 10:53
  • 阅读:481

【报Bug】image组件load事件通过e.mp.detail获取到的宽高小程序和H5不一致

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Windows 10 企业版 21H2

HBuilderX类型: 正式

HBuilderX版本号: 3.4.15

浏览器平台: Chrome

浏览器版本: 102

项目创建方式: HBuilderX

示例代码:
复制代码<template>  
    <view class="banner" style="line-height: 0;">  
        <swiper v-else :autoplay="true" :indicator-dots="true" :interval="interval" :style="bannerStyle">  
            <swiper-item v-for="item in banners" :key="item">  
                <image :src="item" style="width:750rpx;line-height:normal;" mode="widthFix" @load="handleLoaded"></image>  
            </swiper-item>  
        </swiper>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                bannerHeight: 30,  
                banners:['图片路径']  
            };  
        },  
        computed:{  
            bannerStyle() {  
                return `height:${Math.floor(this.bannerHeight)}px`;  
            }  
        },  
        methods: {  
            handleLoaded(e) {  
                const { width, height } = e.mp.detail;  
                console.log('###图片宽高:', width, height);  
                let imgHeight = uni.upx2px(height);  
                const screenWidth = uni.upx2px(750);  
                if (imgHeight>this.bannerHeight) {  
                    if(width<=height){  
                        if (imgHeight<screenWidth)  
                            imgHeight += (screenWidth-imgHeight)/screenWidth*screenWidth;  
                        else if (imgHeight>screenWidth)  
                            imgHeight = screenWidth;  
                    }   
                    this.bannerHeight = imgHeight;  
                }  
            },  
        }  
    }  
</script>

操作步骤:

分别运行程序到H5模拟器和小程序模拟器获取的结果是不一样的

预期结果:

通过 e.mp.detail应该获取到的都是图片真实宽高,或者小程序和H5结果应该是一致的

实际结果:

真实图片为:750*400像素,H5获取的结果是缩放后的,小程序获取到的结果是真实宽高

bug描述:

今天突然发现小程序的Banner高度在H5和小程序表现不一致,测试后发现是image组件的load事件中通过e.mp.detail获取图片宽高信息H5和小程序获取的结果不一致,小程序获取的是图片的真实宽高,H5获取的是物理宽高,之前是没有这个问题的,麻烦DCloud的工程狮们看下是不是BUG。

2022-06-23 10:53 负责人:无 分享
已邀请:
DCloud_UNI_Anne

DCloud_UNI_Anne

DCloud_UNI_GSQ

DCloud_UNI_GSQ

HBuilderX 3.5.0 alpha 已修复

该问题目前已经被锁定, 无法添加新回复

  • 标题 / 粗斜体
  • 代码片段
  • 超链接 / 图片 / 视频
  • 列表 / 引用

文章内容较多时,可以用标题分段 :

## 大标题 
### 小标题

斜体 / 粗体 :

**粗体** 
*斜体*
***粗斜体***

代码片段 :

``` javascript
代码片段
```

超链接 :

[链接文字](链接地址) 例: [百度](http://www.baidu.com)

图片 :

![图片说明](图片地址) 例: ![百度logo](http://www.baidu.com/img/bdlogo.gif)

视频 :

!![视频说明](视频地址) 例: !![优酷视频](http://youku.com)

有序列表 :

1. 123
2. 123
3. 123

无序列表 :

- 123
- 123
- 123

引用 : ( 双回车后结束引用 )

> 引用内容
引用内容
引用内容