vue 下elementui轮播图自适应高度

翻了下api 没有找到对应的属性,所以这里用方法来实现

这里的 autoHeight 就是高度,height属性钱前面要有 :

<el-carousel :interval="5000" arrow="never" :height="autoHeight">
     <el-carousel-item v-for="(banner, index) in banners" :key="index">
        <a :href="banner.extra.tourl">
			<img :src="banner.imgurl" :title="banner.title" class="max-img">
		</a>
     </el-carousel-item>
  </el-carousel>

我们取的banner 是在750像素下高度为145px

 getAutoHeight(){
     let _w = document.documentElement.clientWidth || document.body.clientWidth; ; 
     this.autoHeight = _w * 145 / 375 + 'px';
  }
发布了62 篇原创文章 · 获赞 9 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_37026254/article/details/88894267