Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
How to iterate over a vue getter

I have this getter this.getHouseTypes it returns an array with objects from the vuex store.

But now i want to append 1 item to the array in the shortest way so i was thinking about ... like:

return [...this.getHouseTypes, newObject];

But that gives me an error:

Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.

Does anyone know why this is ?

Any help is welcome !

EDIT: but in the vue inspector it shows the new array with this.getHouseTypes and newObject in it

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Sounds more like you should do something like this:

import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      houseTypes: [],
    }
  }
  // ...
  computed: {
    addHouseType(newType) {
      let houseTypes = this.getHouseTypes();

      this.houseTypes = this.houseTypes.concat(houseTypes).push(newType);

      return this.houseTypes;
    },
    // mix the getters into computed with object spread operator
    ...mapGetters([
      'getHouseTypes',
      // ...
    ])
  }
}

Have a data variable houseTypes, which is an empty array in the beginning.

Mix your getters, with your computed.

Have a computed that adds values to the local houseTypes and merges the store state.

Depending on what you are doing, you might want to split the adding and retrieving the new array.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda