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

197
Views
Nuxt Vuex can't retrieve collection

I'm running some test wih vuex, i have a "dirty" way to retrieve a collection from an api:

component:

import { mapState, mapActions, mapGetters } from "vuex";
export default {  
computed: {
 ...mapState(["categories"]),
  ...mapGetters(["allCategories"])
     ...
 created(){
   this.getCategories();
 },
...
methods: {
 ...mapActions(['getCategories']),
}

and this is my store.js

import axios from 'axios'; 

export const state = () => ({
categories: [],
});

export const getters = {
allCategories: state =>  state.categories
};

export const actions = {
async getCategories({ commit }) {
const response = await axios.get(
  "apiurl"
);
console.log(response.data.data)
commit("setCategories", response.data);
},
};

export const mutations = {
setCategories: (state,categories) => (state.categories = categories)
}

this works, but i'm trying to do a more cleaner way using this tutorial https://www.youtube.com/watch?v=Wdmi4k7sFzU at time 2:06:38.

my index remains the same but in my component just

computed: {
categories(){
  return this.$store.getters.allCategories()  
}
},

but doesn't work, any ideas? or the first aproach is valid?

thanks!

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!