BooksPage.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div class="books-box">
  3. <div
  4. v-for="item in books"
  5. :key="item.id"
  6. class="book-box"
  7. @click="selectBook(item)"
  8. >
  9. <div class="id">{{ item.id }}</div>
  10. <div class="book_name">{{ item.book_name }}</div>
  11. </div>
  12. <van-button round block type="primary" @click="add"> 新增 </van-button>
  13. </div>
  14. </template>
  15. <script setup>
  16. import { useRouter, useRoute } from 'vue-router'
  17. import { ref, onMounted } from 'vue'
  18. import { getAllBook } from '@/api/api'
  19. import { useCommonStore } from '@/store/common'
  20. const commonStore = useCommonStore()
  21. const books = ref([])
  22. const router = useRouter()
  23. onMounted(async () => {
  24. const res = await getAllBook()
  25. console.log(101010, res)
  26. books.value = res.data
  27. })
  28. function selectBook (item) {
  29. window.localStorage.setItem('book', JSON.stringify(item))
  30. window.localStorage.setItem('bookId', item.id)
  31. // const route = useRoute()
  32. router.back()
  33. }
  34. function add() {
  35. router.push('/add_books')
  36. }
  37. </script>
  38. <style scoped lang="scss">
  39. .books-box {
  40. padding: 24px;
  41. .book-box {
  42. text-align: left;
  43. padding: 24px;
  44. border-radius: 12px;
  45. background-color: #fff;
  46. margin-bottom: 24px;
  47. display: flex;
  48. color: black;
  49. .id {
  50. padding-right: 12px;
  51. }
  52. }
  53. }
  54. </style>