graceNvueSwiperCard.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view>
  3. <swiper :style="{width:width, height:height}" class="grace-swiper-card"
  4. :indicator-dots="true" :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. },
  54. data() {
  55. return {
  56. current : 0
  57. }
  58. },
  59. methods:{
  60. swiperchange : function (e) {
  61. this.current = e.detail.current;
  62. this.$emit('swiperchange', this.current)
  63. },
  64. navto : function (e) {
  65. var url = e.currentTarget.dataset.url;
  66. var type = e.currentTarget.dataset.opentype;
  67. switch (type){
  68. case 'switchTab':
  69. uni.switchTab({
  70. url:url
  71. });
  72. break;
  73. case 'navigate':
  74. uni.navigateTo({
  75. url:url
  76. });
  77. break;
  78. case 'redirect':
  79. uni.redirectTo({
  80. url:url
  81. });
  82. break;
  83. case 'redirect':
  84. uni.redirectTo({
  85. url:url
  86. });
  87. break;
  88. default:
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. .grace-swiper-card-item{font-size:0; overflow:hidden;}
  97. </style>