Vue項目中vue-awesome-swiper輪播插件使用實例:

源自開源項目:http://github.crmeb.net/u/bluevue

1,引入插件git

import { swiper, swiperSlide } from "vue-awesome-swiper";複製代碼

2,初始化樣式,綁定標籤github

<swiper class="swiper-wrapper" :options="swiperVip" ref="mySwiper">  
    <swiperSlide class="swiper-slide memberBg" 
    :class="item.class" 
    v-for="(item, index) in vipList" 
    :key="index" 
    :style="{ backgroundImage: 'url(' + item.image + ')' }" >    
    <div class="name">{{ item.name }}</div>    
    <div class="discount">可享受商品折扣: {{ item.discount / 10 }}折
        <span class="iconfont icon-zhekou"></span>    
    </div> 
    <div class="nav acea-row" v-if="item.grade == grade">
        <div class="item" v-for="(val, indexn) in vipComplete" :key="indexn">
            <div class="num">{{ val.new_number }}</div>
            <div>{{ val.real_name }}</div>
        </div>
    </div>
    <div class="lock" v-if="item.grade > grade">
        <span class="iconfont icon-quanxianguanlisuozi"></span>
    該會員等級還沒有解鎖</div>
    <div class="lock" v-if="item.grade < grade">
        <span class="iconfont icon-xuanzhong1"></span>
     已解鎖更高等級</div>  
    </swiperSlide>
</swiper>複製代碼

3,數據操做bash

export default {
  name: "Poster",
  components: {
    swiper,
    swiperSlide
  },
  props: {},
  data: function() {
    return {
      vipList: [], //會員等級列表
      vipRequire: [], //等級要求
      grade: 0, //當前會員等級
      swiperVip: {
        speed: 1000,
        effect: "coverflow",
        slidesPerView: "auto",
        centeredSlides: true,
        coverflowEffect: {
          rotate: 0, // 旋轉的角度
          stretch: -20, // 拉伸   圖片間左右的間距和密集度
          depth: 100, // 深度   切換圖片間上下的間距和密集度
          modifier: 2, // 修正值 該值越大前面的效果越明顯
          slideShadows: false // 頁面陰影效果
        },
        observer: true,
        observeParents: true
      },
      activeIndex: 0//當前滑塊索引
    };
  },
  watch: {
    vipList: function() { //經過數據判斷並切換至對應滑塊
      let that = this;
      if (that.vipList.length > 0) {
        that.vipList.forEach(function(item, index) {
          if (item.is_clear === true) {
            that.swiper.slideTo(index);
            that.activeIndex = index;
            that.grade = item.grade;
          }
        });
      }
    }
  },
  computed: {
    swiper() {//實例swiper對象
      return this.$refs.mySwiper.swiper;
    }
  },
  mounted: function() {
    let that = this;
    that.getInfo();
    that.swiper.on("slideChange", function() { //綁定滑塊切換事件,異步獲取數據
      that.activeIndex = that.swiper.activeIndex;
      that.getTask();
    });
  },
  methods: {
    getInfo: function() {
      let that = this;
      getVipInfo().then(
        res => {
          that.vipList = res.data.list;
        },
        err => {
          that.$dialog.message(err.msg);
        }
      );
    },
    getTask: function() {
      let that = this;
      getVipTask(that.vipList[that.activeIndex].id).then(
        res => {
          that.vipRequire = res.data.list;
        },
        err => {
          that.$dialog.message(err.msg);
        }
      );
    }
  }
};
複製代碼

效果:
app

相關文章
相關標籤/搜索