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

239
Vistas
How mutate data in method computed?

I'm on Vue 3. I have an onclick method which is supposed to modify the value of my props which is a boolean, I have tried several ways, I manage to enter the computed method, but the value of my props does not change

I register my data

data() {
 return {
  showConsommationWindow: false
 }
}

then I tried 3 ways to change the value but none of them worked. The first :

<submit-button v-on:click="showConsommationWindow = true" />

the 2nd : (alert is executed but the data value don't change)

<submit-button v-on:click="showConsommation(true)"/>

  methods: {
    showConsommation(boolValue){
        alert('false')
        this.showConsommationWindow = boolValue;
      }
  }

The last :

<submit-button v-on:click="showConsommation"/>

  methods: {
    showConsommation(){
      if (!this.showConsommationWindow) {
        alert('false')
        this.showConsommationWindow = true;
        return
      }
      this.showConsommationWindow = false;
    }
  },

I really don't understand why my data can't mutate, thanks for your help.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If value comes from a props, it means the parent distributes a boolean to the component. So if you want to change the boolean value, you should probably do:

// in parent

<Component :booleanValue="myBoolean" @changeBooleanValueEvent="changeMyBoolean" />

...

data() {
  return {
    myBoolean: true
  }
}

methods: {
  changeMyBoolean(value) {
    this.myBoolean = value
  }
}

// in component

props: {
  booleanValue: {
    ...
  }
}

methods: {
  showConsommation() {
    this.$emit('changeBooleanValueEvent', false)
  }
}

over 4 years ago · Santiago Trujillo Denunciar
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