Comment.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="container">
  3. <CommentList v-if="userinfo.openId"
  4. type="user"
  5. :comments="comments"></CommentList>
  6. <div v-if='userinfo.openId'>
  7. <div class="page-title">我的图书</div>
  8. <Card v-for="book in books"
  9. :key="book.id"
  10. :book="book"></Card>
  11. <div v-if='!books.length'>暂时还没添加过书,快去添加几本把</div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import {get} from '@/util'
  17. import CommentList from '@/components/CommentList'
  18. import Card from '@/components/Card'
  19. export default {
  20. data () {
  21. return {
  22. comments: [],
  23. books: [],
  24. userinfo: {}
  25. }
  26. },
  27. components: {
  28. CommentList,
  29. Card
  30. },
  31. methods: {
  32. init () {
  33. wx.showNavigationBarLoading()
  34. this.getComments()
  35. this.getBooks()
  36. wx.hideNavigationBarLoading()
  37. },
  38. async getBooks () {
  39. const books = await get('/weapp/booklist', {
  40. openid: this.userinfo.openId
  41. })
  42. this.books = books.list
  43. },
  44. async getComments () {
  45. const comments = await get('/weapp/commentlist', {
  46. openid: this.userinfo.openId
  47. })
  48. this.comments = comments.list
  49. }
  50. },
  51. onPullDownRefresh () {
  52. this.init()
  53. wx.stopPullDownRefresh()
  54. },
  55. onShow () {
  56. if (!this.userinfo.openId) {
  57. let userinfo = wx.getStorageSync('userInfo')
  58. if (userinfo) {
  59. this.userinfo = userinfo
  60. this.init()
  61. }
  62. }
  63. }
  64. }
  65. </script>
  66. <style>
  67. </style>