element-ui 图片轮播组件 根据最高图片高度 设置组件高度

  <div >
      <el-carousel :height="imgHeight+'px'">
        <el-carousel-item v-for='(item , index) in datas.pictureArr' :key="index">
         <img class="slide-picture" :src="item.picUrl" style="width: 375px">
        </el-carousel-item>
      </el-carousel>
    </div>
        $imgWH(img_url){
            return new Promise((resolve, reject) => {
                let img = new Image();
                img.src = img_url;
                img.onload = function(){
                     let imgInfo = {
                        width: img.width,
                        height:  img.height
                     }
                     resolve(imgInfo);
                }
          })
        }
    methods: {
      async bigHeight(){
        let heightArr = [];
        for (let value of this.datas.pictureArr.values()) {
            let info = await this.$imgWH(value.picUrl);
            let h = info.height*375 / info.width;
            heightArr.push(h);
        }
        this.imgHeight = Math.max(...heightArr);
      }
    },

猜你喜欢

转载自blog.csdn.net/qq_26642611/article/details/109513538