Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
Lararvel API with Nuxt

My goal is to pull in two separate data sets under the store directory. Eventually I want to have a categories list and an events list.

I started with a single set in the index.js file.

export const state = () => ({
    categories: []
  })
  
  export const getters = {
    categories (state) {
      return state.categories
    }
  }
  
  export const mutations = {
    SET_CATEGORIES (state, categories) {
      state.categories = categories
    }
  }
  
  export const actions = {
    async nuxtServerInit({ commit, dispatch }) {
      let response = await this.$axios.$get('categories')
  
      commit('SET_CATEGORIES', response.data)
    }
  }

This works exactly as I expect it to.

I copied it over to a category.js file, and changed index.js to

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

Vue.use(Vuex)

import category from './category'

export default new Vuex.Store({
  modules: {
    category
  }
})
 

I expect to get the same list of the categories as before, but instead I get an error 'Cannot read properties of undefined (reading 'getters')'. This solution was suggested on an old Laracasts Forum.

I went back to the Nuxt docs, but they seem to suggest it should look more like

import category from './category'

export const state = () => ({
    category: []
})

When I make these changes, I lose the error, but still don't get any data back. But this doesn't quite look right either anyway.

I have started going in circles with similar solutions, and nothing is quite clicking yet. Any ideas?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda