No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

menus.js 855B

12345678910111213141516171819202122232425262728293031323334
  1. import { defineStore } from "pinia"
  2. export const useMenuStore = defineStore('menus', {
  3. state: () => ({
  4. menus: [],
  5. loading: false,
  6. error: null
  7. }),
  8. actions: {
  9. async fetchMenus() {
  10. this.menus = []
  11. this.loading = true
  12. try {
  13. this.menus = await fetch('menu.json').then((response) => response.json())
  14. } catch (error) {
  15. this.error = error
  16. } finally {
  17. this.loading = false
  18. }
  19. },
  20. async getMenuPerCategory(categoryName) {
  21. await this.fetchMenus()
  22. console.log('nama kategori ' + categoryName)
  23. if (categoryName !== 'all') {
  24. const filteredCategory = this.menus.filter((item) => item.category === categoryName)
  25. console.log(filteredCategory)
  26. this.menus = filteredCategory
  27. } else {
  28. await this.fetchMenus()
  29. }
  30. }
  31. }
  32. })