my-swiper.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view>
  3. <view class="uni-margin-wrap" v-if="list.length>0">
  4. <swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval">
  5. <swiper-item v-for="(item,index) in list" :key="index">
  6. <view class="content " @click="clickImg(item)">
  7. <image class="image " :src="item.imageUrl"></image>
  8. <view class="number-box">
  9. <text class="number">{{ index + 1 }}/{{ list.length }}</text>
  10. </view>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import {getAdsList} from '@/api/home.js';
  19. export default {
  20. name: "my-swiper",
  21. props: {
  22. autoplay: {
  23. type: Boolean,
  24. default () {
  25. return true
  26. },
  27. },
  28. interval: {
  29. type: Number,
  30. default () {
  31. return 3000
  32. },
  33. },
  34. indicatorDots: { //是否显示面板指示点
  35. type: Boolean,
  36. default () {
  37. return false
  38. },
  39. },
  40. type: {
  41. type: Number,
  42. default () {
  43. return -1
  44. },
  45. },
  46. },
  47. data() {
  48. return {
  49. list:[],
  50. };
  51. },
  52. created(){
  53. this.getAdsList(this.type);
  54. },
  55. methods:{
  56. clickImg(item){
  57. console.log("点击了广告图片",item)
  58. //跳转到某个页面,路劲由后端配置
  59. if (item.skipType === 2){//跳转到文章链接
  60. uni.navigateTo({
  61. url: '/pages/groupbuying/article/article?id='+item.dataId
  62. });
  63. }
  64. if (item.skipType === 3){ //跳转到团购详情链接
  65. uni.navigateTo({
  66. url: item.targetUrl
  67. });
  68. }
  69. },
  70. getAdsList(type){
  71. console.log("+++++++++++++++++++++加载广告+++++++++++++++++++++")
  72. getAdsList({
  73. type : type
  74. }).then(res => {
  75. this.list=res.data;
  76. })
  77. }
  78. }
  79. }
  80. </script>
  81. <style>
  82. .uni-margin-wrap {
  83. width: 750rpx;
  84. height: 420rpx;
  85. }
  86. .swiper {
  87. height: 420rpx;
  88. }
  89. .image{
  90. width: 100%;
  91. height: 100%;
  92. }
  93. .content{
  94. width: 750rpx;
  95. height: 420rpx;
  96. position: relative;
  97. }
  98. .number-box{
  99. background-color: rgba(0, 0, 0, 0.3);
  100. border-radius: 6px;
  101. padding: 2rpx 12rpx 2rpx 12rpx;
  102. position: absolute;
  103. left: 10rpx;
  104. top: 10rpx;
  105. }
  106. .number{
  107. overflow-wrap: break-word;
  108. color: rgba(255, 255, 255, 1);
  109. font-size: 20rpx;
  110. font-weight: NaN;
  111. text-align: center;
  112. white-space: nowrap;
  113. line-height: 28rpx;
  114. }
  115. .bord{
  116. border: 1px solid red;
  117. }
  118. </style>