banner.vue 2.1 KB

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