items.js 632 B

12345678910111213141516171819202122232425
  1. import { ref } from 'vue'
  2. import { defineStore } from 'pinia'
  3. export const API_URL = 'https://restaurant.kolei.ru'
  4. /**
  5. * Список блюд
  6. */
  7. export const useItemsStore = defineStore('items', () => {
  8. const itemList = ref([])
  9. const cartList = ref([])
  10. async function getItems () {
  11. if (itemList.value.length == 0) {
  12. const response = await fetch(`${API_URL}`);
  13. if (!response.ok) {
  14. throw new Error('Ошибка при получении списка блюд');
  15. }
  16. itemList.value = await response.json()
  17. }
  18. return itemList.value
  19. }
  20. return { itemList, getItems, cartList }
  21. })