index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="demo-switcher">
  3. <demo-block title="基础用法">
  4. <z-swiper v-model="list" :options="options">
  5. <z-swiper-item v-for="(item,index) in list" :key="index">
  6. <demo-item :item="item"></demo-item>
  7. </z-swiper-item>
  8. </z-swiper>
  9. </demo-block>
  10. <demo-block title="插槽自定义">
  11. <z-swiper v-model="list" :options="optionsSlot">
  12. <z-swiper-item v-for="(item,index) in list" :key="index">
  13. <demo-item :item="item"></demo-item>
  14. </z-swiper-item>
  15. <template #pre-button>
  16. <view class="custom-switcher">
  17. prev
  18. </view>
  19. </template>
  20. <template #next-button>
  21. <view class="custom-switcher">
  22. next
  23. </view>
  24. </template>
  25. </z-swiper>
  26. </demo-block>
  27. <demo-block title="完全自定义">
  28. <z-swiper v-model="loopList" ref="zSwiper" :options="optionsCustom">
  29. <z-swiper-item v-for="(item,index) in loopList" :key="index">
  30. <demo-item :item="item"></demo-item>
  31. </z-swiper-item>
  32. </z-swiper>
  33. <view class="custom-switcher-group">
  34. <button type="primary" size="mini" class="custom-switcher-group-button" @click="prev()">prev</button>
  35. <button type="primary" size="mini" class="custom-switcher-group-button" @click="next()">next</button>
  36. </view>
  37. </demo-block>
  38. </view>
  39. </template>
  40. <script>
  41. import data from '../../common/js/data.js'
  42. export default {
  43. data() {
  44. return {
  45. options: {
  46. navigation: {
  47. nextEl: true,
  48. prevEl: true
  49. },
  50. },
  51. optionsSlot: {
  52. navigation: {
  53. slot: true
  54. },
  55. },
  56. optionsCustom: {
  57. navigation: {
  58. custom: true
  59. },
  60. loop: true
  61. },
  62. list: data,
  63. loopList: data
  64. }
  65. },
  66. methods: {
  67. prev() {
  68. this.$refs.zSwiper.swiper.slidePrev();
  69. },
  70. next() {
  71. this.$refs.zSwiper.swiper.slideNext();
  72. }
  73. }
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .demo-switcher {
  78. .image {
  79. height: 300rpx;
  80. width: 100%;
  81. }
  82. .custom-switcher {
  83. display: flex;
  84. align-items: center;
  85. }
  86. .custom-switcher-group {
  87. margin-top: 20rpx;
  88. display: flex;
  89. align-items: center;
  90. justify-content: space-around;
  91. }
  92. }
  93. </style>