index.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class=" column">
  3. <view class="u-flex-y-center">
  4. <view class="list-item" @click="goLive(item)" v-for="(item,index) in list" :key="index">
  5. {{index}}
  6. </view>
  7. </view>
  8. <!-- <view class="list-item">
  9. </view>
  10. <view class="list-item">
  11. </view> -->
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. liveList
  17. } from '@/api/list'
  18. // import { LiveWS } from '@/utils/liveWS'
  19. // import { login,loginByWeChat,getUserInfo,loginByApple } from '@/api/user'
  20. export default {
  21. data() {
  22. return {
  23. list: null,
  24. }
  25. },
  26. onLoad(option) {
  27. this.getList()
  28. },
  29. methods: {
  30. goLive(item) {
  31. var liveId=item.liveId
  32. uni.setStorageSync('liveId', liveId);
  33. console.log("要传的liveId",liveId)
  34. uni.navigateTo({
  35. url:'/pages/home/living'
  36. // url: `/pages/home/living?liveId=${encodeURIComponent(JSON.stringify(liveId))}`
  37. });
  38. },
  39. getList() {
  40. const data = {
  41. page: 1,
  42. page_size: 10,
  43. };
  44. uni.showLoading({ title: "处理中..." });
  45. liveList(data)
  46. .then(res => {
  47. if (res.code == 200) {
  48. this.list = res.rows; // 直接赋值给 this.list
  49. console.log("list>>", this.list); // ✅ 打印已定义的 this.list
  50. } else {
  51. uni.showToast({ title: res.msg, icon: 'none' });
  52. }
  53. })
  54. .catch(rej => {
  55. console.log("请求失败:", JSON.stringify(rej));
  56. })
  57. .finally(() => {
  58. uni.hideLoading();
  59. });
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .list-item {
  66. width: 100rpx;
  67. height: 100rpx;
  68. background-color: #0082f4;
  69. margin-right: 10rpx;
  70. color: #111;
  71. image {
  72. width: 100%;
  73. height: 100%;
  74. }
  75. }
  76. </style>