Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
Can't access getters in the store for Vue when in a template because it "is not a function"

I'm new to vue and vuex and I'm also using Nuxt. I want to use a function in my template that searches for some data that I fetched from an API (in vuex). I can't figute out why I always get

state.allHandhelds.values.findIndex is not a function

My template is like this:

<div>{{ handheldID("Form Factor") }}</div>

And in my computed I call the function like this:

 computed: {
    ...mapGetters(["allHandhelds"]),
    handheldID(merkmal) {
      return this.$store.getters.indexFinder(merkmal);
    },
  },

In vuex I have it defined as a getter:

export const getters = {
   indexFinder(state, merkmal) {
    return state.allHandhelds.values.findIndex(
      (el) => el === merkmal
    ); /* Index des Merkmals finden */
  },
};

Any idea where I'm going wrong with that?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You've to use the method access style like :

export const getters = {

 indexFinder: (state) => (merkmal) => {
      return state.allHandhelds.values.findIndex(
         (el) => el === merkmal
    ); 
  }
};

or with syntax :

export const getters = {
   indexFinder(state) {
    return (merkmal)=> {
       return state.allHandhelds.values.findIndex(
      (el) => el === merkmal
    ); /* Index des Merkmals finden */
   }  
},
};
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda