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

153
Visualizações
Common functions are not executed in Nuxt.js store

Assumption

I wanted to use inject in Nuxt.js to share the same process, and I wanted to use it in Vuex, so I tried to use it in store, but it would not run. How can I use it?

What we want to achieve

I want to execute common functions in store.

Code

store

this.$axios.$post(`${url.POST_API}poss`, {
      post: {
・
・
・
・
      .catch(() => {
        // commit('alertSwitchError', true)
        // setTimeout(() => {
        //   commit('alertSwitchError', false)
        // }, 3000)
        this.$errorHandling
      })
  }

plugin/responsePocessing

const errorHandling = ({ store }) => {
  store.commit('alertSwitchError', true)
  setTimeout(() => {
    store.commit('alertSwitchError', false)
  }, 3000)
}

export default ({ app }, inject) => {
  inject('errorHandling', errorHandling)
}

nuxt.config.js

・
・
・
  plugins: [
・
・
    'plugins/responsePocessing'
  ],

・
・
・

Error

No error.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the best solution that comes to my mind is to define your errorHandling function in the utils directory, then you can use import to import it in your plugin and import it in your store file seperately.

but if you are not going to use it inside your components or pages i recommend not to create a plugin at all. just create a file in your utils directory, like processUtils.js, then import it in your store.

the thing is plugins where created in nuxt so you can inject functions needed inside your template and script tags, store does not have access to plugins

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