index.js 739 B

123456789101112131415161718192021222324252627282930
  1. export const state = () => ({
  2. heroes: []
  3. })
  4. export const actions = {
  5. async fetchHeroes({state, commit}) {
  6. const heroes = await this.$axios.$get('/api/v1/product-heroes')
  7. if(heroes.isAxiosError === true){
  8. console.log(heroes.data)
  9. return Error('')
  10. }
  11. commit('setHeroes', heroes)
  12. return state.heroes
  13. },
  14. async activateHero({commit}, heroId) {
  15. const activeHero = await this.$axios.$patch(`/api/v1/product-heroes/${heroId}`)
  16. if(activeHero.isAxiosError === true){
  17. console.log(activeHero.data)
  18. return Error('')
  19. }
  20. commit('hero/setHero', activeHero, {root: true})
  21. return activeHero
  22. }
  23. }
  24. export const mutations = {
  25. setHeroes(state, heroes) {
  26. state.heroes = heroes
  27. }
  28. }