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

109
Views
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 answers
Answer question

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 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!