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

167
Visualizações
Set "this" keyword of App.vue in Vuex state

I found a seloution for how to access to vue-router and other services that works only inside the vue component. In the created option of App.vue i save the "this" of vue app inside state of vuex.

does it's a good way or can make some problems in future?

instead to write:

this.$router.push('route-name')

from some component, is save the this keyword in the state as context key for example, and now from the Actions i'm using the context instead this such like this: state.context.router.push('route-name') and its works..

my question is if its good solution or not.

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

0

I think that is not a good solution, if you want to use this, you should try with the actions or getter returned value, inside a Vue file instead using it directly in an action.

I'm giving an example and an explanation

Example:

Getter:

export function getRedirect(state){
 return state.routerName
}

Vue file:

<template>
Page 
<button @onClick="redirect" > Redirect </button>
</template>
<script>
import {mapGetters} from 'vuex'
export default: {
   computed:{
      ...mapGetters('VuexStoreName',['getRedirect'])
   },
   methods:{
        redirect(){
            this.$router.push(this.getRedirect)
        } 
   }
}
</script>

So, instead of using the redirect inside an JS file, creating an action and passing this inside the parameter or getting it by state, you'll be using it correctly in a Vue file.

The probblem setting this in the state is that when it changes the instance saved will not change, and you'll have to update every time and everywhere. And calling this inside a Vue file, it'll always be updated

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