<template>
  <el-carousel :interval="4000" type="card" height="200px">
    <el-carousel-item v-for="item in carouselItems" :key="item">
      <img :src="item.imageUrl" alt="carousel-item" />
    </el-carousel-item>
  </el-carousel>
</template>
<script>
import { ref } from 'vue';

export default {
  setup() {
    const carouselItems = ref([
      { imageUrl: require('@/assets/image1.jpg') },
      { imageUrl: require('@/assets/image2.jpg') },
      { imageUrl: require('@/assets/image3.jpg') },
      // Add more carousel items as needed
    ]);

    return {
      carouselItems
    };
  }
};
</script>
<style scoped>
.el-carousel__item img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
Element Plus 轮播图 Vue 组合式 API 获取静态资源

原文地址: https://www.cveoy.top/t/topic/qzhy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录