banner.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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: "HomeBanner",
  38. data() {
  39. return {
  40. banners: [
  41. {
  42. id: 1,
  43. src: "https://img.shuimuai.com/mp/banner1_new.png",
  44. // src: "",
  45. url: "/pages/none/main",
  46. button_text: "关于水母星球",
  47. },
  48. {
  49. id: 2,
  50. src: "https://img.shuimuai.com/mp/banners/banner3%402x.png",
  51. url: "/pages/competition/main",
  52. button_text: "参加比赛",
  53. },
  54. {
  55. id: 3,
  56. src: "https://img.shuimuai.com/banner_blue.png",
  57. // src: "",
  58. url: "/pages/joint/main",
  59. button_text: "我要联名",
  60. },
  61. ],
  62. };
  63. },
  64. methods: {
  65. to_none($url) {
  66. mpvue.navigateTo({
  67. url: $url,
  68. });
  69. },
  70. getBanners() {
  71. getBannerList().then((res) => {
  72. if(res.data.code == 0){
  73. console.log("活动列表ID:", res);
  74. let $res = res.data;
  75. let $activities = $res.data;
  76. let $new_act = $activities.pop();
  77. console.log("轮播图", $new_act);
  78. $this.banners[1].src = $new_act["img"]
  79. ? "https://img.shuimuai.com/" + $new_act["img"]
  80. : "https://img.shuimuai.com/banner_activity_may_1.png";
  81. $this.banners[1].url =
  82. "/pages/competition/main?activity_id=" + $new_act["activity_id"];
  83. } else {
  84. $this.banners.splice(1, 1);
  85. }
  86. });
  87. },
  88. },
  89. mounted() {
  90. $this.getBanners();
  91. // $this.jointBanner()
  92. },
  93. created() {
  94. $this = this;
  95. },
  96. };
  97. </script>
  98. <style>
  99. #banner_container {
  100. position: relative;
  101. width: 100%;
  102. z-index: 1;
  103. }
  104. .join_button {
  105. position: absolute;
  106. right: 33px;
  107. top: 110px;
  108. z-index: 2;
  109. }
  110. </style>