carousel.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div>
  3. <el-card class="mgb20">
  4. <template #header>基础用法</template>
  5. <el-carousel height="400px">
  6. <el-carousel-item v-for="item in 4" :key="item">
  7. <h3>{{ item }}</h3>
  8. </el-carousel-item>
  9. </el-carousel>
  10. </el-card>
  11. <el-row :gutter="20">
  12. <el-col :span="12">
  13. <el-card class="mgb20">
  14. <template #header>轮播图</template>
  15. <el-carousel height="300px">
  16. <el-carousel-item v-for="item in imgs" :key="item">
  17. <el-image class="carousel-img" :src="item" fit="cover" />
  18. </el-carousel-item>
  19. </el-carousel>
  20. </el-card>
  21. </el-col>
  22. <el-col :span="12">
  23. <el-card class="mgb20">
  24. <template #header>卡片模式</template>
  25. <el-carousel height="300px" type="card">
  26. <el-carousel-item v-for="item in imgs" :key="item">
  27. <el-image class="carousel-img" :src="item" fit="cover" />
  28. </el-carousel-item>
  29. </el-carousel>
  30. </el-card>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. </template>
  35. <script lang="ts" setup>
  36. const imgs = [
  37. 'https://cdn.pixabay.com/photo/2017/08/07/08/23/sea-2601374_640.jpg',
  38. 'https://cdn.pixabay.com/photo/2020/02/11/10/24/lake-4839058_640.jpg',
  39. 'https://cdn.pixabay.com/photo/2024/02/21/08/06/coast-8587004_640.jpg',
  40. 'https://cdn.pixabay.com/photo/2023/07/29/10/21/grasshopper-8156626_640.jpg',
  41. ];
  42. </script>
  43. <style scoped>
  44. .el-carousel__item h3 {
  45. color: #475669;
  46. line-height: 400px;
  47. margin: 0;
  48. text-align: center;
  49. }
  50. .el-carousel__item:nth-child(2n) {
  51. background-color: #99a9bf;
  52. }
  53. .el-carousel__item:nth-child(2n + 1) {
  54. background-color: #d3dce6;
  55. }
  56. .carousel-img {
  57. width: 100%;
  58. height: 100%;
  59. }
  60. </style>