BigSwiper.vue 4.3 KB

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