I would like to have a property dynamically accessed with a variable.
For example, I have :
data(){
redsection : '',
bluesection : '',
},
methods(){
changeColor(color, val){
this.{color+"section"} = val;
}
}
And what I'm trying to do it have a function in the view:
<button @click="changeColor("blue", "bar")>blue</button>
<button @click="changeColor("red", "bar")>blue</button>
Use an indexer.
this[color+"section"] = val;
Here is an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With