Estoy en Vue 3. Tengo un método onclick que se supone que modifica el valor de mis accesorios, que es un valor booleano, lo he intentado de varias maneras, logro ingresar el método calculado, pero el valor de mis accesorios no cambia
registro mis datos
data() { return { showConsommationWindow: false } }luego probé 3 formas de cambiar el valor pero ninguna funcionó. El primero :
<submit-button v-on:click="showConsommationWindow = true" />el 2do: (la alerta se ejecuta pero el valor de los datos no cambia)
<submit-button v-on:click="showConsommation(true)"/> methods: { showConsommation(boolValue){ alert('false') this.showConsommationWindow = boolValue; } }El último :
<submit-button v-on:click="showConsommation"/> methods: { showConsommation(){ if (!this.showConsommationWindow) { alert('false') this.showConsommationWindow = true; return } this.showConsommationWindow = false; } },Realmente no entiendo por qué mis datos no pueden mutar, gracias por su ayuda.
Si el valor proviene de accesorios, significa que el padre distribuye un valor booleano al componente . Entonces, si desea cambiar el valor booleano, probablemente debería hacerlo:
// 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) } }