Home.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script setup>
  2. import { ref } from "vue";
  3. // 用于sse请求 对sse进行了封装 支持post携带参数请求 文档: https://www.npmjs.com/package/@microsoft/fetch-event-source
  4. import { fetchEventSource } from "@microsoft/fetch-event-source";
  5. const images = ["image0.png", "image1.png", "image2.png", "image3.png"];
  6. const currentIndex = ref(0);
  7. setInterval(() => {
  8. currentIndex.value = (currentIndex.value + 1) % images.length;
  9. }, 5000); // 切换图片间隔时间(毫秒)
  10. </script>
  11. <template>
  12. <div class="main">
  13. <div class="bg">
  14. <img
  15. :class="currentIndex === index ? 'active' : ''"
  16. v-for="(item, index) in images"
  17. :key="item"
  18. :src="item"
  19. />
  20. </div>
  21. </div>
  22. </template>
  23. <style scoped>
  24. .main {
  25. width: 100vw;
  26. height: 100vh;
  27. overflow: hidden;
  28. }
  29. .bg {
  30. position: fixed;
  31. top: 0;
  32. left: 0;
  33. right: 0;
  34. bottom: 0;
  35. display: flex;
  36. justify-content: center;
  37. align-items: center;
  38. }
  39. .bg img {
  40. position: absolute;
  41. top: 0;
  42. left: 0;
  43. transition: all 0.5s ease-in-out;
  44. opacity: 0;
  45. }
  46. .bg img.active {
  47. opacity: 1;
  48. }
  49. </style>