vue-006中实现轮播图效果

vue中实现轮播图效果

安装swiper 和 vue-awesome-swiper

npm i swiper vue-awesome-swiper@3 -S

template

<template>
  <div class="wrapper">
    <swiper ref="mySwiper"  v-bind:options="swiperOptions">
        <swiper-slide v-for="(item, index) in getUrlList"       v-bind:key="index">
            <img :src="item" alt="">  
        </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",
        },
      },
        imgList: ["ban-inu1.png","ban-lun2.png","ban-lun3.png","ban-lun4.png","ban-lun5.png"]
    };
  },

computed

computed:{
      getUrlList(){
          return this.imgList.map(item=>{
              return require('../assets/img/' + item)
          })
             }
         },

注册子组件

components: {
    swiper,
    swiperSlide,
    }

style样式

.swiper-container {
        background: #f00;
   }
.swiper-slide {
        height: 150px;
   }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容