<template>
    <el-carousel class="banner" :interval="5000" arrow="always">
      <el-carousel-item v-for="item in imgList" :key="item">
         <img :src="item.url" alt />
      </el-carousel-item>
    </el-carousel>
</template>
<script>
export default {
  name: "Banner",
  data() {
    return {
      // 图片地址
    imgList: [
         {
           url:require('../../assets/image/banner1.jpg')
         },
        {
         url:require('../../assets/image/banner1.jpg')
        },
        {
         url:require('../../assets/image/banner1.jpg')
        }
      ],
      // 图片父容器高度
      bannerHeight: 400,
      // 浏览器宽度
      screenWidth: 0
    };
  },
  methods: {
    setSize: function() {
      // 通过浏览器宽度(图片宽度)计算高度
      this.bannerHeight = (400 / 600) * this.screenWidth;
    }
  },
  mounted() {
    // 首次加载时,需要调用一次
    this.screenWidth = window.innerWidth;
    this.setSize();
    // 窗口大小发生改变时,调用一次
    window.onresize = () => {
      this.screenWidth = window.innerWidth;
      this.setSize();
    };
  }
};
</script>
<style scoped>
  .banner{margin-bottom:32px;}
.el-carousel__item h3 {
  color: #34bfa3;
  font-size: 14px;
  opacity: 0.75;
  line-height: 330px;
  margin: 0;
}
.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}
.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
img{
  width:100%;height:100%;
}
.el-carousel__container{
  height:319px;
  }
</style>
