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

107
Visualizações
Loop Store Dispatch

I want to loop over a array with object through a function to create per object a call through store dispatch.

const action = [{ action: 'FILE_CREATE'}, {action: 'MEDIA_CREATE}]

Call the function:

saveComponent(action)

Function

const saveComponent = async (actions, actionOption, redirect, reload) => {
  await Promise.all(actions.map(obj =>
    store.dispatch(Actions[obj.action]).then(() => {
      console.log(obj.action + ' test ')
      }).catch((error) => {
        Swal.fire({
                text: "Sorry, looks like there are some errors detected, please try again.",
                icon: "error",
                buttonsStyling: false,
                confirmButtonText: "Ok, got it!",
                customClass: {
                confirmButton: "btn btn-primary",
                },
            });
            return false;
    }).finally(() => {
        loading.value = false;
    })
  ));
}

The error on console I get is the following: Uncaught (in promise) Error: [vuex] expects string as the type, but found undefined. which results on the following line: store.dispatch(Actions[obj.action])

If I delete the store.dispatch function, and replace it with: console.log(obj.action) it shows the correct data. Also if I just create one store.dispatch function without the Promise.all. It does work. The actions are registered and working fully.

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
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