Vue使用轮播图vue-awesome-swiper组件常用属性-swiper案例

我会带着你远行 2022-09-05 01:57 411阅读 0赞

vue-awesome-swiper

20210816180708815.gif

安装

  1. npm install vue-awesome-swiper@3

引用

  1. /*全局引入*/
  2. import VueAwesomeSwiper from 'vue-awesome-swiper';
  3. import "swiper/dist/css/swiper.css"; //这里注意具体看使用的版本是否需要引入样式,以及具体位置
  4. Vue.use(VueAwesomeSwiper, /* { default global options } */);
  5. /*组件方式引用*/
  6. import { swiper, swiperSlide } from 'vue-awesome-swiper'
  7. import 'swiper/dist/css/swiper.css'这里注意具体看使用的版本是否需要引入样式,以及具体位置
  8. export default {
  9. components: {
  10. swiper,
  11. swiperSlide
  12. }

使用

  1. <div class="recommendPage">
  2. <swiper :options="swiperOption" ref="mySwiper">
  3. <swiper-slide v-for="(item,index) in swiperList" :key="index">
  4. {
  5. {item.text}}
  6. </swiper-slide>
  7. <!-- 滚动条 -->
  8. <div class="swiper-scrollbar" slot="scrollbar"></div>
  9. <!-- 标页码 -->
  10. <div class="swiper-pagination" slot="pagination"></div>
  11. <!-- 上一页 -->
  12. <div class="swiper-button-prev" slot="button-prev"></div>
  13. <!-- 下一页 -->
  14. <div class="swiper-button-next" slot="button-next"></div>
  15. </swiper>
  16. </div>
  17. // 局部引入插件
  18. import { swiper, swiperSlide } from "vue-awesome-swiper";
  19. import "swiper/dist/css/swiper.css";
  20. export default {
  21. components: {
  22. swiper,
  23. swiperSlide,
  24. },
  25. data() {
  26. return {
  27. swiperList:[
  28. { text:"I'm Slide 1",},
  29. { text:"I'm Slide 2",},
  30. { text:"I'm Slide 3",},
  31. { text:"I'm Slide 4",},
  32. { text:"I'm Slide 5",},
  33. { text:"I'm Slide 6",},
  34. ],
  35. swiperOption: {
  36. loop: true,
  37. notNextTick: true, // notNextTick是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true
  38. slidesPerView: 3, //数量
  39. spaceBetween: 30, //间距
  40. slidesPerGroup: 1, //分几组
  41. direction: "horizontal", //设置水平还是垂直vertical
  42. // grabCursor: true, //光标样式
  43. // setWrapperSize: true,
  44. // autoHeight: true,
  45. // centeredSlides: true,
  46. // paginationClickable: true,
  47. // keyboard: true, //键盘控制
  48. // mousewheelControl: true, //鼠标轮控制
  49. autoplay: {
  50. delay: 3000, //自动切换的时间间隔,单位ms
  51. stopOnLastSlide: false, //当切换到最后一个slide时停止自动切换
  52. disableOnInteraction: false, //用户操作swiper之后,是否禁止autoplay
  53. // reverseDirection: false, //开启反向自动轮播
  54. // waitForTransition: true, //等待过渡完毕。自动切换会在slide过渡完毕后才开始计时
  55. },
  56. // 显示分页
  57. pagination: {
  58. el: ".swiper-pagination",
  59. clickable: true, //允许分页点击跳转
  60. },
  61. // 设置点击箭头
  62. navigation: {
  63. nextEl: ".swiper-button-next",
  64. prevEl: ".swiper-button-prev",
  65. },
  66. },
  67. };
  68. },
  69. computed: {
  70. swiper() {
  71. return this.$refs.mySwiper.swiper;
  72. },
  73. },
  74. mounted() {
  75. // current swiper instance
  76. // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
  77. console.log("this is current swiper instance object", this.swiper);
  78. // this.swiper.slideTo(3, 1000, false);
  79. //只有一张图片时不轮播
  80. // this.swiperOption.autoplay =
  81. // this.swiperList.length != 1
  82. // ? {
  83. // disableOnInteraction: false, // 用户操作swiper之后,是否禁止autoplay
  84. // delay: 3000, // 自动切换的时间间隔(单位ms)
  85. // }
  86. // : false;
  87. },
  88. };

可选参数列表

  1. fadeEffect: {
  2. crossFade: false,
  3. }
  4. cubeEffect: {
  5. slideShadows: true, //开启slide阴影。默认 true。
  6. shadow: true, //开启投影。默认 true。
  7. shadowOffset: 100, //投影距离。默认 20,单位px。
  8. shadowScale: 0.6 //投影缩放比例。默认0.94。
  9. },
  10. coverflowEffect: {
  11. rotate: 30, //slide做3d旋转时Y轴的旋转角度。默认50。
  12. stretch: 10, //每个slide之间的拉伸值,越大slide靠得越紧。 默认0。
  13. depth: 60, //slide的位置深度。值越大z轴距离越远,看起来越小。 默认100。
  14. modifier: 2, //depth和rotate和stretch的倍率,相当于depth*modifier、rotate*modifier、stretch*modifier,值越大这三个参数的效果越明显。默认1。
  15. slideShadows : true //开启slide阴影。默认 true。
  16. },
  17. flipEffect: {
  18. slideShadows : true, //slides的阴影。默认true。
  19. limitRotation : true, //限制最大旋转角度为180度,默认true。
  20. }
  21. zoom: {
  22. maxRatio: 5, //最大倍数
  23. minRatio: 2, //最小倍数
  24. toggle: false, //不允许双击缩放,只允许手机端触摸缩放。
  25. containerClass: 'my-zoom-container', //zoom container 类名
  26. },
  27. navigation: {
  28. nextEl: '.swiper-button-next', //前进按钮的css选择器或HTML元素。
  29. prevEl: '.swiper-button-prev', //后退按钮的css选择器或HTML元素。
  30. hideOnClick: true, //点击slide时显示/隐藏按钮
  31. disabledClass: 'my-button-disabled', //前进后退按钮不可用时的类名。
  32. hiddenClass: 'my-button-hidden', //按钮隐藏时的Class
  33. },
  34. pagination: {
  35. el: '.swiper-pagination',
  36. type: 'bullets',
  37. //type: 'fraction',
  38. //type : 'progressbar',
  39. //type : 'custom',
  40. progressbarOpposite: true, //使进度条分页器与Swiper的direction参数相反
  41. bulletElement : 'li', //设定分页器指示器(小点)的HTML标签。
  42. dynamicBullets: true, //动态分页器,当你的slide很多时,开启后,分页器小点的数量会部分隐藏。
  43. dynamicMainBullets: 2, //动态分页器的主指示点的数量
  44. hideOnClick: true, //默认分页器会一直显示。这个选项设置为true时点击Swiper会隐藏/显示分页器。
  45. clickable: true, //此参数设置为true时,点击分页器的指示点分页器会控制Swiper切换。
  46. },
  47. scrollbar: {
  48. el: '.swiper-scrollbar',
  49. hide: true, //滚动条是否自动隐藏。默认:false,不会自动隐藏。
  50. draggable: true, //该参数设置为true时允许拖动滚动条。
  51. snapOnRelease: true, //如果设置为false,释放滚动条时slide不会自动贴合。
  52. dragSize: 30, //设置滚动条指示的尺寸。默认'auto': 自动,或者设置num(px)。
  53. },

发表评论

表情:
评论列表 (有 0 条评论,411人围观)

还没有评论,来说两句吧...

相关阅读