Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!