BigSwiper.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="swiper" v-if="imagelist">
  3. <el-carousel :interval="5000" arrow="always" height="405px" indicator-class="custom-indicator"
  4. class="custom-carousel" @change="handleIndicatorChange">
  5. <el-carousel-item v-for="(item, index) in imagelist" :key="index">
  6. <NuxtLink :to="`/newsDetail/${item.id}`"
  7. :title="item.title">
  8. <img :src="item.imgurl" :alt="item.title">
  9. <span>{{ item.title }}</span>
  10. </NuxtLink>
  11. </el-carousel-item>
  12. <template #indicator="{ index }">
  13. <button :class="{ 'active-indicator': currentIndex === index }">{{ index + 1 }}</button>
  14. </template>
  15. </el-carousel>
  16. </div>
  17. </template>
  18. <script setup>
  19. import { ElCarousel, ElCarouselItem } from 'element-plus'
  20. //获取焦点图数据 start---------------------------------------->
  21. const imagelist = ref("")
  22. async function getModelData1() {
  23. const mkdata = await requestDataPromise('/web/getWebsiteArticlett', {
  24. method: 'GET',
  25. query: {
  26. 'pageSize': 5,
  27. 'level': 2,
  28. 'placeid': 0
  29. },
  30. });
  31. if(mkdata.code == 200){
  32. imagelist.value = mkdata.data;
  33. }else{
  34. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  35. console.log("错误位置:获取首页轮播图")
  36. console.log("后端错误反馈:",mkdata.message)
  37. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  38. }
  39. }
  40. getModelData1()
  41. // let imagelist = ref([])
  42. // async function getModelData1() {
  43. // const { data: mkdata, error: mkdataError } = requestData('/web/getWebsiteArticlett', {
  44. // method: 'GET',
  45. // query: {
  46. // 'pageSize': 5,
  47. // 'level': 2,
  48. // 'placeid': 0
  49. // },
  50. // });
  51. // if (mkdataError.value) {
  52. // //console.error('模块1数据上部分请求失败!', mkdataError.value);
  53. // } else {
  54. // if (mkdata.value) {
  55. // //console.log('模块1数据上部分请求成功!', mkdata.value.data);
  56. // imagelist.value = mkdata.value.data;
  57. // }
  58. // }
  59. // }
  60. // getModelData1()
  61. //获取焦点图数据 end---------------------------------------->
  62. let currentIndex = ref(0)
  63. let handleIndicatorChange = (val) => {
  64. currentIndex.value = val
  65. }
  66. </script>
  67. <style lang="less" scoped>
  68. .swiper {
  69. width: 720px;
  70. height: 405px;
  71. position: relative;
  72. img {
  73. width: 720px;
  74. height: 405px;
  75. }
  76. span {
  77. display: inline-block;
  78. width: 720px;
  79. height: 118px;
  80. padding-top: 20px;
  81. padding-left: 23px;
  82. box-sizing: border-box;
  83. position: absolute;
  84. top: 0;
  85. left: 0;
  86. font-family: Source Han Sans, Source Han Sans;
  87. font-weight: 800;
  88. font-size: 24px;
  89. color: #FFFFFF;
  90. background: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
  91. }
  92. }
  93. .el-carousel {
  94. // 左右箭头按钮
  95. .el-carousel__arrow--right :deep(.class-name),
  96. .el-carousel__arrow--left :deep(.class-name) {
  97. width: 68px;
  98. height: 68px;
  99. }
  100. //左右箭头图片
  101. /deep/.el-icon svg {
  102. height: 1em;
  103. width: 1em;
  104. background-color: transparent;
  105. }
  106. /deep/.el-carousel__arrow {
  107. border-radius: 0;
  108. background-color: transparent;
  109. }
  110. /deep/.el-carousel__arrow i {
  111. font-size: 68px !important;
  112. }
  113. /deep/ .el-carousel__indicators {
  114. // 指示器
  115. left: unset;
  116. transform: unset;
  117. right: 41%;
  118. }
  119. /deep/ .el-carousel__button {
  120. // 指示器按钮
  121. width: 20px;
  122. height: 20px;
  123. border-radius: 50%;
  124. border: none;
  125. opacity: 1;
  126. background-color: #FFFFFF;
  127. }
  128. /deep/ .is-active .el-carousel__button {
  129. // 指示器激活按钮
  130. background: #46D333;
  131. }
  132. /deep/ .el-carousel__container {
  133. height: 100%;
  134. }
  135. /deep/.custom-indicators {
  136. position: absolute;
  137. bottom: 10px;
  138. left: 50%;
  139. transform: translateX(-50%);
  140. }
  141. // 将指示器的所有样式都不显示
  142. // /deep/.el-carousel__indicators {
  143. // display: none;
  144. // }
  145. }
  146. </style>