I am trying to implement a button that triggers the raiseStat() function. The goal is to pass the name of an existing variable so that the function can modify that specific variable.
Here is the button:
<button @click="raiseStat(health)">Add</button>
The data containing the variable to be modified:
data(){
return{
health: 1,
}
},
This is the function itself:
methods: {
raiseStat(statName){
statName++
},
},
When I console.log the variable within the function, it displays '1' as expected because only the value is being passed through, not the name.
Is there a way to reference the name of the variable instead of just its value?
Thank you