[Vuejs]-Why is my Vuex state not changing after nuxtServerInit commit?

-1👍

import Vue from 'vue'
import Vuex from 'vuex'

import { createClient } from '~/plugins/contentful'

const client = createClient()

export default = () => new Vuex.Store({
  state: {
    categories: {}
  },

  mutations: {
    addCategories (state, data) {
      Vue.$set(state, 'categories', [...data.items, ...state.catagories])
    },
  },

  actions: {
    async nuxtServerInit ({ commit }) {    
      let response

      try {
        response = await client.getEntries({ content_type: 'category' })
      }
      catch (error) {
        console.log(error)
      }

      context.commit('addCategories', response)
    },
})

Leave a comment