swiper在vue中引用

1.在vue中使用 首先 npm install --save swiper@5 // 安装低版本的最好,这里装5.x
2.安装结束后,直接复制下面代码。哪里需要放哪里,组件直接用就好了

<template>
  <div id="swipercom">
    <div class="swiper-container" id="swiperIndex">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item, i) in imgs" :key="i">
          <img :src="item.pic" alt="" />
        </div>
      </div>
      //换页器
      <div class="swiper-pagination"></div>
    </div>
  </div>
</template>
 
<script>
import "swiper/css/swiper.css"; //引入swiper样式
import Swiper from "swiper"; //引入swiper
export default {
  name: "Swiper",
  data() {
    return {
      imgs: [
        { pic: require("../assets/img/dy.jpg") },
        { pic: require("../assets/img/dy.jpg") },
        { pic: require("../assets/img/dy.jpg") },
      ],
    };
  },
  mounted() {
    var mySwiper = new Swiper("#swiperIndex", {
      //配置分页器内容
      direction: "vertical",
      mousewheel: true,
      loop: true, // 循环模式选项
      pagination: {
        el: ".swiper-pagination", //换页器与哪个标签关联
        clickable: true, //分页器是否可以点击
      },
 
 
    });
  },
};
</script>
 
<style >
.swiper-container {
  width: 80%;
  height: 400px;
  border-radius: 0.1rem;
}
.swiper-slide img {
  width: 100%;
}
.swiper-pagination-bullet {
  background-color: white;
}
.swiper-pagination-bullet-active {
  background-color: orangered;
}
</style>

你可能感兴趣的:(vue,vue.js,javascript,前端)