HomeView.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="container home">
  3. <main>
  4. <section class="carousel">
  5. <h2>热门商品轮播</h2>
  6. <div class="carousel-images" :style="{ transform: `translateX(-${currentIndex * 100}%)` }">
  7. <div v-for="(image, index) in images" :key="index" :style="{ width: '100%', height: '100%' }">
  8. <img :src="image.src" :alt="image.alt" style="width: 100%; height: 100%;" />
  9. </div>
  10. </div>
  11. </section>
  12. <section class="featured-products">
  13. <h2>推荐商品</h2>
  14. <div class="product-list">
  15. <div class="product-item">
  16. <img src="@/assets/img/project_view.png" alt="Product 1" />
  17. <p>产品1 - 描述</p>
  18. <button @click="addToCart({ id: 1, name: '产品1', description: '这是产品1的描述', price: '100元' })">加入购物车</button>
  19. </div>
  20. <div class="product-item">
  21. <img src="@/assets/img/prompt_view.png" alt="Product 2" />
  22. <p>产品2 - 描述</p>
  23. <button @click="addToCart({ id: 2, name: '产品2', description: '这是产品2的描述', price: '200元' })">加入购物车</button>
  24. </div>
  25. <div class="product-item">
  26. <img src="@/assets/img/upload_view.png" alt="Product 3" />
  27. <p>产品3 - 描述</p>
  28. <button @click="addToCart({ id: 3, name: '产品3', description: '这是产品3的描述', price: '300元' })">加入购物车</button>
  29. </div>
  30. </div>
  31. </section>
  32. <section class="categories">
  33. <h2>商品分类</h2>
  34. <!-- 商品分类导航 -->
  35. </section>
  36. </main>
  37. <footer>
  38. <p>&copy; 2025 Prototype Design. All rights reserved.</p>
  39. </footer>
  40. </div>
  41. </template>
  42. <script setup>
  43. import { ref, onMounted } from 'vue'
  44. import projectView from '../assets/img/project_view.png';
  45. import promptView from '../assets/img/prompt_view.png';
  46. import uploadView from '../assets/img/upload_view.png';
  47. const images = [
  48. { src: projectView, alt: 'Product 1' },
  49. { src: promptView, alt: 'Product 2' },
  50. { src: uploadView, alt: 'Product 3' }
  51. ]
  52. const currentIndex = ref(0)
  53. const nextImage = () => {
  54. currentIndex.value = (currentIndex.value + 1) % images.length
  55. }
  56. onMounted(() => {
  57. setInterval(nextImage, 2000)
  58. })
  59. const addToCart = (product) => {
  60. // 在这里实现添加到购物车的逻辑
  61. }
  62. </script>
  63. <style scoped>
  64. .carousel-images {
  65. display: flex;
  66. overflow: hidden;
  67. transition: transform 0.5s ease-in-out;
  68. width: 100%; /* 修改为100%以适应父容器 */
  69. height: 400px; /* 确保容器有足够的高度 */
  70. position: relative; /* 添加相对定位 */
  71. }
  72. .carousel-images img {
  73. width: 100%; /* 每张图片占据整个容器的宽度 */
  74. height: 100%; /* 图片高度占满容器高度 */
  75. object-fit: cover; /* 确保图片完全覆盖容器 */
  76. position: absolute; /* 添加绝对定位 */
  77. top: 0;
  78. left: 0;
  79. right: 0;
  80. bottom: 0;
  81. }
  82. </style>