vue-awesome-swiper@4 在v2项目的模板

vue-awesome-swiper@4 在v2项目的模板

我在练习时常用的vue-awesome-swiper@4模板,欢迎补充!

<template>
	<Swiper style="height: 100%" ref="mySwiper" :options="options">
          <SwiperSlide v-for="(item, index) in bannerArr" :key="index">
            <img :src="item.imgUrl" alt="" />
          </SwiperSlide>
          <div class="swiper-pagination" slot="pagination"></div>
          <div class="swiper-button-prev" slot="button-prev"></div>
          <div class="swiper-button-next" slot="button-next"></div>
   </Swiper>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "xxx",
  computed: {
    ...mapState({
      data数据: (state) => state.仓库名.state数据,
    }),
    mySwiper() {
      return this.$refs.mySwiper;
    },
  },
  data() {
    return {
      options: {
        // 自动切换
        autoplay: {
          delay: 1000,
          stopOnLastSlide: false,
          disableOnInteraction: true,
        },
        // 环路
        loop: true,
        // 前进后退按钮
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
        // 分页器
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        // 切换效果cube
        effect: "cube",
      },
    };
  },
  mounted() {
    this.mySwiper.$el.onmouseenter = () => {
      this.mySwiper.$swiper.autoplay.stop();
    };
    this.mySwiper.$el.onmouseleave = () => {
      this.mySwiper.$swiper.autoplay.start();
    };
  },
};
</script>

main.js入口文件里声明swiper全局组件:

import {Swiper,SwiperSlide} from 'vue-awesome-swiper'
import "swiper/css/swiper.min.css";
Vue.component('Swiper',Swiper)
Vue.component('SwiperSlide',SwiperSlide)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值