Imagine you are working on a Vue JS application and have some states defined like this:
data () {
optionA: {
xaxis: { categories: ['DD'] }
}
}
There is also a method in your app that takes a state as a parameter:
modifyOption (optionName, xAxisCategory, dataLabelsEnabled) {
optionName = {
...optionName,
...{
xAxis: { categories: xAxisCategory },
dataLabels: { enabled: dataLabelsEnabled }
}
}
}
The optionName
parameter, as shown in the example usage below, is expected to be a state name when calling the method:
this.mofifyOption(this.optionA, 'DD MMM', true)
If you want the method to modify the state directly without having to reference its value, you can try something like this:
modifyOption (this.optionA, 'DD MMM', true) {
this.optionA = {
...this.optionA,
...{
xAxis: { categories: 'DD MMM' },
dataLabels: { enabled: true }
}
}
}
In this scenario, you only pass this.optionA
directly without accessing its value. Is there a way to achieve this?