BigSwiper.vue 3.2 KB

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