美文网首页
vue中实现轮播图效果

vue中实现轮播图效果

作者: alicemum | 来源:发表于2021-03-16 15:32 被阅读0次

安装swiper 和 vue-awesome-swiper

npm i swiper vue-awesome-swiper -S

template

<template>
  <div class="wrapper">
    <swiper ref="mySwiper" v-bind:options="swiperOptions">
      <swiper-slide v-for="(item, index) in 5" v-bind:key="index">
          {{item}}
      </swiper-slide>

      <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>
  </div>
</template>

引入组件和css

import { swiper, swiperSlide } from "vue-awesome-swiper";
import "swiper/swiper-bundle.css";

data数据

data() {
    return {
      swiperOptions: {
        loop: true,
        speed: 2000,
        autoplay: {
          delay: 3000,

          stopOnLastSlide: false,
          disableOnInteraction: false,
        },
        // 显示分页
        pagination: {
          el: ".swiper-pagination",
          clickable: true, //允许分页点击跳转
        },
        // 设置点击箭头
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
      },
    };
  },

注册子组件

components: {
    swiper,
    swiperSlide,
  }

style样式

.swiper-container {
        background: #f00;
   }
.swiper-slide {
        height: 150px;
   }

相关文章

网友评论

      本文标题:vue中实现轮播图效果

      本文链接:https://www.haomeiwen.com/subject/ykblcltx.html