App.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <main class="main">
  3. <div
  4. class="menu"
  5. :style="`flex: calc(100% - ${cartWidth}px);`"
  6. >
  7. <menu-item
  8. v-for="(item, index) in itemList"
  9. :key="index"
  10. :item="item"
  11. />
  12. </div>
  13. <div
  14. v-if="cartList.length > 0"
  15. class="cart"
  16. >
  17. <cart-item-vue
  18. v-for="(item, index) in cartList"
  19. :key="index"
  20. :item="item"/>
  21. <div>
  22. Итого: {{ itog }}
  23. </div>
  24. </div>
  25. </main>
  26. </template>
  27. <script setup>
  28. import { storeToRefs } from 'pinia'
  29. import { useItemsStore } from '/src/stores/items.js'
  30. import MenuItem from '/src/components/MenuItem.vue'
  31. import CartItemVue from '/src/components/CartItem.vue'
  32. import { computed } from 'vue'
  33. import { calcItog } from './helpers/common'
  34. const menuStore = useItemsStore()
  35. const { itemList, cartList } = storeToRefs(menuStore)
  36. const cartWidth = computed(() => {
  37. return cartList.value.length ? 300 : 0
  38. })
  39. const itog = computed(() => {
  40. return calcItog(cartList.value)
  41. })
  42. menuStore.getItems()
  43. </script>
  44. <style scoped>
  45. .main {
  46. width: 100%;
  47. display: flex;
  48. }
  49. .menu {
  50. display: inline-block;
  51. /* background-color: burlywood; */
  52. }
  53. .cart {
  54. display: inline-block;
  55. /* background-color: bisque; */
  56. flex: 300px;
  57. }
  58. </style>