BigSwiper.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <!-- 首页大的轮播图 -->
  3. <div class="swiper">
  4. <el-carousel :interval="5000" arrow="always" height="440px" 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. target="_blank">
  9. <img :src="item.imgurl" alt="">
  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. import { onMounted } from 'vue'
  22. const nuxtApp = useNuxtApp();
  23. const axios = nuxtApp.$axios;
  24. let imagelist = useState("imageList", () => "")
  25. let lunbo = async () => {
  26. try {
  27. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${5}&level=${2}&placeid=${0}`);
  28. // console.log(response.data);
  29. imagelist.value = response.data;
  30. } catch (error) {
  31. console.error(error);
  32. }
  33. }
  34. onMounted(() => {
  35. lunbo()
  36. })
  37. let currentIndex = ref(0)
  38. let handleIndicatorChange = (val) => {
  39. currentIndex.value = val
  40. }
  41. </script>
  42. <style lang="less" scoped>
  43. .swiper {
  44. width: 790px;
  45. height: 440px;
  46. position: relative;
  47. img {
  48. width: 790px;
  49. height: 440px;
  50. }
  51. span {
  52. display: inline-block;
  53. width: 790px;
  54. height: 118px;
  55. padding-top: 20px;
  56. padding-left: 23px;
  57. box-sizing: border-box;
  58. position: absolute;
  59. top: 0;
  60. left: 0;
  61. font-family: Source Han Sans, Source Han Sans;
  62. font-weight: 800;
  63. font-size: 24px;
  64. color: #FFFFFF;
  65. background: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
  66. }
  67. }
  68. .el-carousel {
  69. // 左右箭头按钮
  70. .el-carousel__arrow--right :deep(.class-name),
  71. .el-carousel__arrow--left :deep(.class-name) {
  72. width: 68px;
  73. height: 68px;
  74. }
  75. //左右箭头图片
  76. /deep/.el-icon svg {
  77. height: 1em;
  78. width: 1em;
  79. background-color: transparent;
  80. }
  81. /deep/.el-carousel__arrow {
  82. border-radius: 0;
  83. background-color: transparent;
  84. }
  85. /deep/.el-carousel__arrow i {
  86. font-size: 68px !important;
  87. }
  88. /deep/ .el-carousel__indicators {
  89. // 指示器
  90. left: unset;
  91. transform: unset;
  92. right: 41%;
  93. }
  94. /deep/ .el-carousel__button {
  95. // 指示器按钮
  96. width: 20px;
  97. height: 20px;
  98. border-radius: 50%;
  99. border: none;
  100. opacity: 1;
  101. background-color: #FFFFFF;
  102. }
  103. /deep/ .is-active .el-carousel__button {
  104. // 指示器激活按钮
  105. background: #46D333;
  106. }
  107. /deep/ .el-carousel__container {
  108. height: 100%;
  109. }
  110. /deep/.custom-indicators {
  111. position: absolute;
  112. bottom: 10px;
  113. left: 50%;
  114. transform: translateX(-50%);
  115. }
  116. // 将指示器的所有样式都不显示
  117. // /deep/.el-carousel__indicators {
  118. // display: none;
  119. // }
  120. }
  121. </style>