graceNvueSwiperCard.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view>
  3. <swiper :style="{width:width, height:height}" class="grace-swiper-card" :current="currentIndex"
  4. :indicator-dots="indicatorDots" :interval="interval" :indicator-color="indicatorColor" :indicator-active-color="indicatorActiveColor" :circular="true" :autoplay="autoplay" @change="swiperchange">
  5. <swiper-item v-for="(item, index) in swiperItems" :key="index" class="grace-swiper-card-item">
  6. <view :data-url="item.url" :data-opentype="item.opentype" @tap="navto">
  7. <image :style="{borderRadius : borderRadius, width:width, height:height}"
  8. :src="item.img" class="grace-swiper-card-image" mode="widthFix" />
  9. </view>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. </template>
  14. <script>
  15. export default{
  16. props:{
  17. width:{
  18. type : String,
  19. default : "750rpx"
  20. },
  21. height:{
  22. type : String,
  23. default : "300rpx"
  24. },
  25. swiperItems : {
  26. type : Array,
  27. default : function(){return new Array();}
  28. },
  29. borderRadius : {
  30. type : String,
  31. default : '5rpx'
  32. },
  33. indicatorColor : {
  34. type : String,
  35. default : "rgba(0, 0, 0, 0.2)"
  36. },
  37. indicatorActiveColor : {
  38. type : String,
  39. default : "#3688FF"
  40. },
  41. spacing : {
  42. type : String,
  43. default : "50rpx"
  44. },
  45. interval : {
  46. type : Number,
  47. default : 5000
  48. },
  49. autoplay : {
  50. type : Boolean,
  51. default : true
  52. },
  53. currentIndex : {
  54. type : Number,
  55. default : 0
  56. },
  57. indicatorDots:{
  58. type : Boolean,
  59. default:true
  60. }
  61. },
  62. data() {
  63. return {
  64. current : 0
  65. }
  66. },
  67. watch:{
  68. currentIndex : function (val) {
  69. this.current = val;
  70. }
  71. },
  72. created:function(){
  73. this.current = this.currentIndex;
  74. },
  75. methods:{
  76. swiperchange : function (e) {
  77. this.current = e.detail.current;
  78. this.$emit('swiperchange', this.current);
  79. },
  80. navto : function (e) {
  81. var url = e.currentTarget.dataset.url;
  82. var type = e.currentTarget.dataset.opentype;
  83. switch (type){
  84. case 'switchTab':
  85. uni.switchTab({
  86. url:url
  87. });
  88. break;
  89. case 'navigate':
  90. uni.navigateTo({
  91. url:url
  92. });
  93. break;
  94. case 'redirect':
  95. uni.redirectTo({
  96. url:url
  97. });
  98. break;
  99. default:
  100. break;
  101. }
  102. }
  103. }
  104. }
  105. </script>
  106. <style scoped>
  107. .grace-swiper-card-item{font-size:0; overflow:hidden;}
  108. </style>