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

143
Visualizações
Vue - dynamically created computed property not found on page refresh

I have these computed properties in a component:

computed: {
  messageText: {
    get() {
      return this.getMessageProp('messageText') // Maps to a vuex getter
    },
    set(value) {
      this.setMessageProp(['messageText', value]) // Maps to a vuex mutation
    }
  },
  location: {
    get() {
      return this.getMessageProp('location')
    },
    set(value) {
      this.setMessageProp(['location', value])
    }
  }
}

This works on browser refresh. As you can see it's a bit repetitive (There are a few more in other components).

I tried to create them dynamically like this:

data() {
  return {
    stepProps: {
      messageText: {},
      location: {},
    }
  }
},
created() {
  Object.keys(this.stepProps).forEach((key) => {
    if (!this.$options.computed[key]) {
      this.$options.computed[key] = {
        get() {
          return this.getMessageProp(key)
        },
        set(value) {
          this.setMessageProp([key, value])
        }
      }
    }
  })
}

But it does not work on browser refresh. I get the error:

Property or method "messageText" is not defined on the instance but referenced during render....

It works when switching components (I am using Vue router)

How can I get this, or something similar, to work? Ultimately I wanted to put it into a mixin to reuse in other components.

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