index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view class="related-books">
  3. <view class="books-grid">
  4. <view v-for="(book, index) in books" :key="index" class="book-item" @click="onBookClick(book)">
  5. <image :src="book.cover" mode="aspectFill" class="book-cover"></image>
  6. <text class="book-title u-line-1">{{ book.title }}</text>
  7. <text class="book-edition u-line-1">{{ book.edition }}</text>
  8. </view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'RelatedBooks',
  15. props: {
  16. books: {
  17. type: Array,
  18. default: () => []
  19. }
  20. },
  21. methods: {
  22. onBookClick(book) {
  23. this.$emit('click', book);
  24. }
  25. }
  26. }
  27. </script>
  28. <style lang="scss" scoped>
  29. .related-books {
  30. background: transparent;
  31. padding-top: 20rpx;
  32. .books-grid {
  33. display: flex;
  34. flex-wrap: wrap;
  35. margin: 0 -10rpx; /* Compensate for item padding */
  36. .book-item {
  37. width: 33.33%;
  38. padding: 0 10rpx 30rpx 10rpx;
  39. box-sizing: border-box;
  40. display: flex;
  41. flex-direction: column;
  42. .book-cover {
  43. width: 100%;
  44. height: 280rpx;
  45. border-radius: 8rpx;
  46. background: #eee;
  47. margin-bottom: 12rpx;
  48. }
  49. .book-title {
  50. font-size: 26rpx;
  51. color: #333;
  52. font-weight: 500;
  53. margin-bottom: 4rpx;
  54. }
  55. .book-edition {
  56. font-size: 22rpx;
  57. color: #999;
  58. }
  59. }
  60. }
  61. }
  62. </style>