hero.js 715 B

1234567891011121314151617181920212223242526272829303132
  1. export const state = () => ({
  2. item: {}
  3. })
  4. export const actions = {
  5. async createHero({commit, state}, courseHeroData) {
  6. const hero = await this.$axios.$post('/api/v1/product-heroes', courseHeroData)
  7. if(hero.isAxiosError === true){
  8. console.log(data.data)
  9. return Error('')
  10. }
  11. commit('setHero', hero)
  12. return state.item
  13. },
  14. async fetchHero({commit, state}) {
  15. const data = await this.$axios.$get('/api/v1')
  16. if(data.isAxiosError === true){
  17. console.log(data.data)
  18. return Error('')
  19. }
  20. const { productHero } = data
  21. commit('setHero', productHero)
  22. return state.item
  23. }
  24. }
  25. export const mutations = {
  26. setHero(state, hero) {
  27. state.item = hero
  28. }
  29. }