<template>
  <div>
    <div class="home-head">
      <swiper ref="mySwiper" :options="swiperOptions" class="item-swiper">
        <swiper-slide v-for="(item, index) in swiperList" :key="index">
          <router-link :to="`/news/detail?id=${item.id}&type=home`">
            <img :src="item" alt="" />
          </router-link>
        </swiper-slide>
      </swiper>
    </div>
  </div>
</template>
<script>
import { swiper, swiperSlide, directive } from 'vue-awesome-swiper'
export default {
  components: {
    swiper,
    swiperSlide
  },
  directives: {
    swiper: directive
  },
  data() {
    const _this = this
    return {
      swiperList: ['https://zws-imgs-pub.ezijing.com/static/public/3dceecce8df0a6dcb06d48c75ada807b.png'],
      swiperOptions: {
        on: {
          slideChangeTransitionStart: function() {
            _this.swiperIndex = this.activeIndex
          }
        },
        observer:true,//修改swiper自己或子元素时，自动初始化swiper 
        observeParents:true,//修改swiper的父元素时，自动初始化swiper 
        loop:true,
        autoplay: {
          delay: 2000,
          disableOnInteraction: false
        }
      }
    }
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper
    }
  }
}
</script>
<style lang="scss" scoped>
.home-head{
  img{
    width: 100%;
    display: block;
  }
}
</style>
