Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda