微信小程序 动态计算图片大小
方法一 使用图片的mode属性

手动计算
- 给图片绑定事件
bind:load,回调函数名为onImgLoad - 编写回调函数,width为340是图片容器的宽度
methods: {
onImgLoad(event){
// 图片的高宽数据在event.detail中
const {width, height} = event.detail
this.setData({
w:340,
h:340/width*height
})
}
}
- 数据返回给图片
<image bind:load="onImgLoad" style="width:{{w}}rpx;height:{{h}}rpx" src="{{data.img}}"/>

3108

被折叠的 条评论
为什么被折叠?



