banner.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div id="banner_container">
  3. <!-- <img src="https://img.shuimuai.com/mp/banners/banner1%402x.png" class="full_img main_banner" alt="">-->
  4. <swiper
  5. class="screen-swiper round-dot full_img main_banner"
  6. :indicator-dots="true"
  7. :circular="true"
  8. :autoplay="true"
  9. interval="5000"
  10. duration="500"
  11. >
  12. <swiper-item
  13. v-for="(item,index) in banners"
  14. :key="index"
  15. class="full_img main_banner"
  16. >
  17. <img
  18. :src="item.src"
  19. mode="aspectFill"
  20. class="full_img main_banner"
  21. >
  22. <button
  23. class="cu-btn bg-yellow text-white join_button"
  24. @click="to_none(item.url)"
  25. >{{
  26. item.button_text
  27. }}
  28. </button>
  29. </swiper-item>
  30. </swiper>
  31. </div>
  32. </template>
  33. <script>
  34. import { getBannerList } from "../requests/user";
  35. var $this;
  36. export default {
  37. name: "banner",
  38. data() {
  39. return {
  40. banners: [
  41. {
  42. id: 1,
  43. src: "https://img.shuimuai.com/mp/banner1_new.png",
  44. url: "/pages/none/main",
  45. button_text: "关于水母星球",
  46. },
  47. {
  48. id: 2,
  49. src: "https://img.shuimuai.com/mp/banners/banner3%402x.png",
  50. url: "/pages/competition/main",
  51. button_text: "比赛详情",
  52. },
  53. ],
  54. };
  55. },
  56. methods: {
  57. to_none($url) {
  58. mpvue.navigateTo({
  59. url: $url,
  60. });
  61. },
  62. getBanners() {
  63. getBannerList().then((res) => {
  64. console.log("活动列表ID:", res);
  65. let $res = res.data;
  66. let $activities = $res.data;
  67. let $new_act = $activities.pop();
  68. // console.log("轮播图", $new_act);
  69. $this.banners[1].src = $new_act["img"]
  70. ? "https://img.shuimuai.com/" + $new_act["img"]
  71. : "https://img.shuimuai.com/banner_activity_may_1.png";
  72. $this.banners[1].url =
  73. "/pages/competition/main?activity_id=" + $new_act["activity_id"];
  74. });
  75. },
  76. },
  77. mounted() {
  78. $this.getBanners();
  79. },
  80. created() {
  81. $this = this;
  82. },
  83. };
  84. </script>
  85. <style>
  86. #banner_container {
  87. position: relative;
  88. width: 100%;
  89. z-index: 1;
  90. }
  91. .join_button {
  92. position: absolute;
  93. right: 33px;
  94. top: 110px;
  95. z-index: 2;
  96. }
  97. </style>