index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class=" content ">
  3. <view class="list">
  4. <view class="list-item" @click="goLive(item)" v-for="(item,index) in list" :key="index">
  5. <image :src="item.liveImgUrl"></image>
  6. <view class="info">
  7. <text>{{item.liveName}}</text>
  8. </view>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import {
  15. liveList
  16. } from '@/api/list'
  17. // import { LiveWS } from '@/utils/liveWS'
  18. // import { login,loginByWeChat,getUserInfo,loginByApple } from '@/api/user'
  19. export default {
  20. data() {
  21. return {
  22. list: null,
  23. liveId:null
  24. }
  25. },
  26. onLoad(option) {
  27. this.getList()
  28. },
  29. methods: {
  30. goLive(item) {
  31. this.liveId = item.liveId
  32. console.log("要传的liveId", this.liveId)
  33. uni.navigateTo({
  34. url: '/pages/home/living?liveId='+this.liveId
  35. // url: `/pages/home/living?liveId=${encodeURIComponent(JSON.stringify(liveId))}`
  36. });
  37. },
  38. getList() {
  39. const data = {
  40. page: 1,
  41. page_size: 10,
  42. };
  43. uni.showLoading({
  44. title: "处理中..."
  45. });
  46. liveList(data)
  47. .then(res => {
  48. if (res.code == 200) {
  49. this.list = res.rows; // 直接赋值给 this.list
  50. console.log("list>>", this.list); // ✅ 打印已定义的 this.list
  51. } else {
  52. uni.showToast({
  53. title: res.msg,
  54. icon: 'none'
  55. });
  56. }
  57. })
  58. .catch(rej => {
  59. console.log("请求失败:", JSON.stringify(rej));
  60. })
  61. .finally(() => {
  62. uni.hideLoading();
  63. });
  64. }
  65. }
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .content {
  70. background-color: #111;
  71. min-height: 100vh;
  72. padding: 24rpx;
  73. .list {
  74. display: flex;
  75. justify-content: space-between;
  76. flex-wrap: wrap;
  77. .list-item {
  78. border-radius: 16rpx;
  79. width: 340rpx;
  80. height: 600rpx;
  81. background-color: #0082f4;
  82. margin-right: 10rpx;
  83. margin-bottom: 24rpx;
  84. overflow: hidden;
  85. position: relative;
  86. .info {
  87. position: absolute;
  88. left: 20rpx;
  89. bottom: 14rpx;
  90. color: #ffffff;
  91. }
  92. image {
  93. width: 100%;
  94. height: 100%;
  95. }
  96. }
  97. }
  98. }
  99. </style>