zhihu.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <v-container class="grey lighten-5">
  3. <v-row justify="space-between">
  4. <v-col>
  5. <v-row dense justify="center">
  6. <question-card :question="question" />
  7. </v-row>
  8. <v-row dense>
  9. <div v-infinite-scroll="loadMore" infinite-scroll-disabled="true" infinite-scroll-distance="10">
  10. <v-col cols="12">
  11. <v-row
  12. v-for="item in cardList"
  13. :key="item.answerId"
  14. justify="center"
  15. >
  16. <answer-card :answer="item" />
  17. </v-row>
  18. </v-col>
  19. </div>
  20. </v-row>
  21. </v-col>
  22. <v-col md="4">
  23. <v-row dense>
  24. <v-col cols="12">
  25. <v-card
  26. color="#385F73"
  27. light
  28. >
  29. <v-card-title class="text-h5">
  30. 热门问题
  31. </v-card-title>
  32. <v-card-text>
  33. <p class="text-body-1 text--primary">
  34. 1.第1条
  35. </p>
  36. <p class="text-body-1 text--primary">
  37. 2.第2条
  38. </p>
  39. </v-card-text>
  40. </v-card>
  41. </v-col>
  42. <v-col cols="12">
  43. <v-card
  44. color="#385F73"
  45. light
  46. >
  47. <v-card-title class="text-h5">
  48. 热门回答
  49. </v-card-title>
  50. <v-card-text>
  51. <p class="text-body-1 text--primary">
  52. 1.第1条
  53. </p>
  54. <p class="text-body-1 text--primary">
  55. 2.第2条
  56. </p>
  57. </v-card-text>
  58. </v-card>
  59. </v-col>
  60. </v-row>
  61. </v-col>
  62. </v-row>
  63. <v-snackbar
  64. v-model="showMessage"
  65. :top="true"
  66. :timeout="3000"
  67. >
  68. {{ message }}
  69. <template v-slot:action="{ attrs }">
  70. <v-btn
  71. color="pink"
  72. text
  73. v-bind="attrs"
  74. @click="showMessage = false"
  75. >
  76. 关闭
  77. </v-btn>
  78. </template>
  79. </v-snackbar>
  80. </v-container>
  81. </template>
  82. <script>
  83. import { answerRecommend } from '@/api/mblog/status'
  84. import AnswerCard from '@/components/card/answer-card'
  85. import QuestionCard from '@/components/card/question-card'
  86. export default {
  87. name: 'Home',
  88. components: {
  89. QuestionCard,
  90. AnswerCard
  91. },
  92. data() {
  93. return {
  94. question: {
  95. title: '你最照骗的一张照片是什么样子?',
  96. detail: ''
  97. },
  98. cardList: [],
  99. busy: false,
  100. page: 1,
  101. showMessage: false,
  102. message: ''
  103. }
  104. },
  105. created() {
  106. this.getFollowingStatus(this.page)
  107. },
  108. mounted() {
  109. },
  110. methods: {
  111. loadMore: function() {
  112. this.busy = true
  113. setTimeout(() => {
  114. console.log('加载更多数据')
  115. }, 1000)
  116. },
  117. getFollowingStatus(page) {
  118. answerRecommend(page)
  119. .then(res => {
  120. if (res.code === 0) {
  121. if (page === 1) {
  122. this.cardList = []
  123. }
  124. for (const item of res.data.list) {
  125. this.cardList.push(item)
  126. }
  127. this.page += 1
  128. this.busy = false
  129. } else {
  130. this.message = res.msg
  131. this.showMessage = true
  132. }
  133. })
  134. .catch(error => {
  135. this.message = error.message
  136. this.showMessage = true
  137. })
  138. }
  139. }
  140. }
  141. </script>
  142. <style>
  143. </style>