当前位置:   article > 正文

vue2 中 使用Swiper多张卡片轮播图,解决vue-element固定三张卡片式。_vue轮播图三张图片展示

vue轮播图三张图片展示

1.安装swiper

(官网:Swiper中文网-轮播图幻灯片js插件,H5页面前端开发

下载轮播图插件【注意:要@5.x】,不然会出现各种BUG。

npm i swiper@5.x vue-awesome-swiper@4.1.1 -S

2.HTML代码

  1. <template>
  2. <div class="swiper">
  3. <div @mouseleave="leave" @mouseenter="enter">
  4. <swiper ref="mySwiper" :options="swiperOption">
  5. <swiper-slide v-for="(item, index) in clist"
  6. :key="item.imgUrl + index">
  7. <img :src="item.imgUrl" />
  8. </swiper-slide>
  9. </swiper>
  10. </div>
  11. <div @mouseenter="enter" @mouseleave="leave">
  12. <div class="swiper-button-prev"></div>
  13. <div class="swiper-button-next"></div>
  14. </div>
  15. </div>
  16. </template>

3.JS代码

  1. <script>
  2. import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
  3. import 'swiper/css/swiper.css'
  4. export default {
  5. components: {
  6. Swiper,
  7. SwiperSlide
  8. },
  9. data () {
  10. return {
  11. clist: [
  12. {
  13. imgUrl: require('/src/assets/images/certify01.png')
  14. },
  15. {
  16. imgUrl: require('/src/assets/images/certify02.png')
  17. },
  18. {
  19. imgUrl: require('/src/assets/images/certify03.png')
  20. },
  21. {
  22. imgUrl: require('/src/assets/images/certify04.png')
  23. }
  24. ,
  25. {
  26. imgUrl: require('/src/assets/images/certify05.png')
  27. }
  28. ],
  29. swiperOption: {
  30. // 衔接滑动
  31. loop: true,
  32. // 自动滑动
  33. autoplay: {
  34. delay: 2000,
  35. // 如果设置为true,当切换到最后一个slide时停止自动切换。
  36. stopOnLastSlide: false,
  37. // 如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay
  38. disableOnInteraction: false
  39. },
  40. // 切换效果 "coverflow"(3d流)
  41. effect: 'coverflow',
  42. // 设置slider容器能够同时显示的slides数量
  43. slidesPerView: 4,
  44. // 居中幻灯片。设定为true时,当前的active slide 会居中,而不是默认状态下的居左。
  45. centeredSlides: true,
  46. // 设置为true则点击slide会过渡到这个slide。
  47. slideToClickedSlide: true,
  48. coverflowEffect: {
  49. // slide做3d旋转时Y轴的旋转角度
  50. rotate: 0,
  51. // 每个slide之间的拉伸值,越大slide靠得越紧。5.3.6 后可使用%百分比
  52. stretch: 0,
  53. // slide的位置深度。值越大z轴距离越远,看起来越小。
  54. depth: 60,
  55. // depth和rotate和stretch的倍率,相当于depth*modifier、rotate*modifier、stretch*modifier,值越大这三个参数的效果越明显。
  56. modifier: 5,
  57. // 是否开启slide阴影
  58. slideShadows: true
  59. },
  60. // 使用前进后退按钮来控制Swiper切换。
  61. navigation: {
  62. nextEl: '.swiper-button-next',
  63. prevEl: '.swiper-button-prev'
  64. }
  65. },
  66. }
  67. },
  68. computed: {
  69. mySwiper () {
  70. // mySwiper 是要绑定到标签中的ref属性
  71. return this.$refs.mySwiper.$swiper
  72. }
  73. },
  74. methods:{
  75. enter () {
  76. this.mySwiper.autoplay.stop()
  77. },
  78. leave () {
  79. this.mySwiper.autoplay.start()
  80. },
  81. }
  82. }
  83. </script>

4.css代码

  1. <style scoped lang="scss">
  2. .swiper{
  3. width:1200px;
  4. margin: 0 auto;
  5. padding-top: 50px;
  6. padding-bottom: 40px;
  7. }
  8. .swiper-button-prev{
  9. }
  10. </style>

 以上图片大小为300X300

注意:swiperOption里面的值配合宽度自己调试

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/251188
推荐阅读
相关标签
  

闽ICP备14008679号