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

83
Views
La matriz no está definida en Veux Store

Estoy recuperando datos de la Tienda Vuex. En primer lugar, quiero verificar si la matriz está presente en la tienda Vuex, luego quiero verificar si el objeto noProducts en el índice 0 no está presente.

La razón de esto es que tweakwiseSortedProducts se usa para ambos productos y un booleano sin productos para reaccionar en el front-end

 tweakwiseHasProducts () { if (this.$store.state.tweakwise?.tweakwiseSortedProducts) { return ( this.$store.state.tweakwise.tweakwiseSortedProducts[0].noProducts === false ); } return false; },

Mi front-end actualmente, a menudo, devuelve:

 this.$store.state.tweakwise.tweakwiseSortedProducts[0] is undefined

en la consola

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esto sucede porque tweakwiseSortedProducts no está unificado sino una lista vacía. Puedes probar:

 tweakwiseHasProducts () { if (this.$store.state.tweakwise?.tweakwiseSortedProducts?.length !== 0) { return ( this.$store.state.tweakwise.tweakwiseSortedProducts[0].noProducts === false ); } return false; },

o solo:

 tweakwiseHasProducts () { return this.$store.state.tweakwise?.tweakwiseSortedProducts[0]?.noProducts === false; },

que será falso si alguno de estos elementos no está definido, o verdadero si noProducts es realmente falso

about 4 years ago · Juan Pablo Isaza Report

0

Se recomienda usar getter al llamar a un valor en Vuex.
Por favor refiérase a la siguiente.

 getters: { getTweakwiseSortedProducts: (state: any) => { return state.tweakwise?.tweakwiseSortedProducts || []; }, },

 tweakwiseHasProducts () { this.$store.getters.getTweakwiseSortedProducts.length ? true : false; }
about 4 years ago · Juan Pablo Isaza Report
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!