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

371
Views
Nuxt / Vuex: use un captador asíncrono en otra propiedad calculada

Tienda / acciones.js

 export default { async fetchData(context, route) { const dataURL = `myUrl.json`; const response = await fetch(dataURL); const responseData = await response.json(); let arr = []; if (!response.ok) { const error = new Error(responseData.message || 'Failed to fetch requests.'); throw error; } // Commit arr to mutation arr = responseData; context.commit('addArr', arr); }, }

Tienda / mutaciones.js

 export default{ addArr(state, payload) { state.arr = payload; } }

Tienda / estado.js

 export default () => ({ arr: [] })

Tienda / getters.js

 export default { getArr(state) { return state.arr; } }

Vue / myComponent.vue

 <template> <div> <pre> THIS WORKS FINE {{getArr}} </pre> <pre> THIS WORKS FINE {{myArr1}} </pre> <pre> THIS WORKS FINE {{myArr2}} </pre> <pre> THIS WORKS FINE {{myArr2}} </pre> <div v-for="(item, index) in sortArr" :key="item.id"> {{item.name}} .... </div> </div> </template> <script> import {mapGetters} from 'vuex'; export default { name: "myComponent", computed: { ...mapGetters(['getArr']), myArr1() { return this.getArr; }, myArr2() { return this.$store.getters.getArr; }, sortArr() { const unsortedArr = this.$store.getters.getArr; // const unsortedArr = this.myArr1; // const unsortedArr = this.myArr2; // Does not work, always returns empty array console.log(unsortedArr); let sortedArr = []; .... // unsortedArr gets now manipulated.. a lot of magic happens here.. return sortedArr; }, }, methods: { async fetchData() { await this.$store.dispatch('fetchData'); }, }, async created() { await this.fetchData; }, } </script>

Creo que tengo una falta fundamental de comprensión, cómo funcionan los getters de vuex.... Pensé que podría obtener mi matriz de getters y trabajar con ella en mi componente. Pero no es posible asignar el valor de mi getter a una variable y usarlo en otra propiedad o método calculado.

¿Hay una mejor manera de hacer esto? ¿Qué me estoy perdiendo? ¿Y cuál sería la solución para usar mi lista ordenada y manipulada de elementos en mi componente?

¡Gracias!

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!