vue框架中使用swiper滑动组件

Swiper滑动组件功能很强大也广泛应用于移动端打造滑动、触屏等功能,官网:https://www.swiper.com.cn/,说下在Vue中使用Swiper。

1.下载安装

用npm的方式:npm install swiper

2.组件中引入

import Swiper from ‘swiper’; 
import ‘swiper/dist/css/swiper.min.css’;

3.使用

<template>
  <div class="demo">
    <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for= "(item,index) in swiperList">
        <div class="box-c">{{item}}</div>
      </div>
    </div>
  </div>
  </div>
</template>

<script>
import Swiper from "swiper";
import "swiper/dist/css/swiper.min.css";

export default {
  name: "HelloWorld",
  data() {
    return {
      swiperList: []
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.swiperList = [5, 6, 7, 8];
      setTimeout(function() {
        var mySwiper = new Swiper(".swiper-container", {
          slidesPerView: 3,
          loop: true,
          autoplay: {
            delay: 3000,
            disableOnInteraction: false
          }
        });
      }, 100);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.demo {
  width: 350px;
}
.box-c {
  width: 100px;
  height: 50px;
  border: 1px solid #000;
}
</style>

 

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值