vue-轮播

  • 安装swiper cnpm install --save swiper
  • dom结构:
<template>
  <div class="swiper-container fileSwiper">
    <div class="swiper-wrapper">
       <slot></slot> <!--插槽 -->
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>
  </div>
</template>
  • 引入swiper: import Swiper from 'swiper'
 mounted() {
    console.log("swiper-mounted");
    /* eslint-disable no-new */
    new Swiper(".fileSwiper", {  //构造函数初始化
      // direction: 'vertical'
      loop: true,
      autoplay: { // 自动轮播
      	deplay: 20000 // 2秒
      },
      // 如果需要分页器
      pagination: {
        el: ".swiper-pagination"
      }
    });
  }
  • 构造函数报错的话就在上一行加上注释: /* eslint-disable no-new */,具体原因不知,能解决就可!
<script>
import swiper from './File/Swiper'
export default {
  components: {
    swiper
  }
}
</script>
  • 引入组件: import swiper from '@/views/File/Swiper'
  • 导入样式: import 'swiper/css/swiper.min.css'
  • 测试轮播内容:
<swiper>
	<div class="swiper-slide" v-for="n in 10" :key="n">{{n}}</div>
</swiper>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值