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

235
Visualizações
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 Respostas
Responde à pergunta

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 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