how can I simplify this switch? Is there an easier way to write a switch like that? Or to return as in the switch depending on the 5 cases I have?
data() {
return {
stepOneIsCompleted: false,
stepTwoIsCompleted: false,
stepThreeIsCompleted: false,
stepFourIsCompleted: false,
stepFiveIsCompleted: false,
};
},
updateViewEditVisibility(step, status) {
switch (step) {
case 1:
status === 200 ? this.stepOneIsCompleted = true : this.stepOneIsCompleted = false;
break;
case 2:
status === 200 ? this.stepTwoIsCompleted = true : this.stepOneIsCompleted = false;
break;
case 3:
status === 200 ? this.stepThreeIsCompleted = true : this.stepOneIsCompleted = false;
break;
case 4:
status === 200 ? this.stepFourIsCompleted = true : this.stepOneIsCompleted = false;
break;
case 5:
status === 200 ? this.stepFiveIsCompleted = true : this.stepOneIsCompleted = false;
break;
}
},
It should be mentioned that I will send those values as props. Couldn't I make an array for example and look in it according to step and assign a value to it?
data() {
return {
stepCompleted: [
false, //stepOneIsCompleted
false, //stepTwoIsCompleted
false, //...
false,
false
]
}
}
...
updateViewEditVisibility(step, status) {
this.stepCompleted[step] = status === 200;
}