uniapp css 展示图片原始大小不压缩或者拉伸图片

获取图片信息,并赋值

vue:
  <image
          :src="url"
          class="img"
       
          :style="{
            width: width,
            height: height,
          }"
        />


js:
 data() {
    return {
      width: "",
      height: "",
    };
  },
  mounted() {
    let that = this;
    uni.getImageInfo({
      src: url,
      success: (image) => {
        that.width = image.width + "rpx";
        that.height = image.height + "rpx";
        console.log(that.width, image.width, that.height, image.height);
      },
    });
  },

css:防止横向图片超出显示
.img {
  max-width: 100%;
  max-height: 100%;
}

你可能感兴趣的:(uni-app,css,前端)