如果要保持图片在容器内不变形可设置mode属性为aspectFit
代码如下:
//wxml
<view class="content">
<image src="/images/1.png" class="img" mode="aspectFit"></image>
</view>
//wxss
.content{
width:200rpx;
height:200rpx;
display:flex;
justify-content: center;
align-items: center;
border:solid 1rpx #cecece;
}
.img{
max-width: 150rpx;
max-height: 150rpx;
}
效果如下图: