I am writing a step through form and need to access the ref for each step in my Axios catch block in a DRY way.
Below, where it says stepOneObserver
, I need stepTwoObserver
, stepThree
, stepFour
, etc.
this.$refs.stepOneObserver.setErrors(error.response.data.errors);
Is it possible to use a variable for this?
if (observerStep === 1) {
var obsStep = 'stepOneObserver';
}
this.$refs.{obsStep}.setErrors(error.response.data.errors);
I'm pseudo-coding, but basically want the {obsStep}
to act as if it said stepOneObserver
and reference that in the code.
Hope this is clear enough / makes sense.