App.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div class="main">
  3. <MainHeader />
  4. <MainBody />
  5. <!-- 遮罩层颜色渐变区域 -->
  6. <div class="mask" ref="mask">
  7. <!-- 视频背景区域 -->
  8. <video
  9. v-if="currentPath === '/'"
  10. class="video_background"
  11. preload="auto"
  12. loop
  13. playsinline
  14. autoplay
  15. muted
  16. src="@/assets/videos/1.mp4"
  17. ></video>
  18. </div>
  19. </div>
  20. </template>
  21. <script setup lang="ts">
  22. import { watch, ref } from "vue";
  23. import { useRoute } from "vue-router";
  24. // 路由实例
  25. const $route = useRoute();
  26. // 遮罩层DOM元素
  27. const mask = ref();
  28. // 当前路由路径
  29. const currentPath = ref("");
  30. // 监听当前路由路径变化
  31. watch($route, (newValue) => {
  32. currentPath.value = newValue.path;
  33. if (currentPath.value !== "/") {
  34. mask.value.style.backgroundColor = "rgb(2, 2, 28)";
  35. } else {
  36. mask.value.style.backgroundColor = "";
  37. }
  38. });
  39. </script>
  40. <style lang="scss" scoped>
  41. .main {
  42. position: relative;
  43. width: 7072px;
  44. height: 1872px;
  45. overflow: hidden;
  46. .mask {
  47. position: absolute;
  48. top: 0;
  49. left: 0;
  50. width: 100%;
  51. height: 100%;
  52. .video_background {
  53. width: 100%;
  54. height: 100%;
  55. object-fit: cover;
  56. background-image: radial-gradient(
  57. rgba(0, 6, 15, 0) 0%,
  58. rgba(0, 6, 15, 0.8) 90%,
  59. rgba(0, 6, 15, 1) 100%
  60. );
  61. }
  62. }
  63. }
  64. </style>