То, что я пытаюсь сделать, это:
validateStep(stepNumber) {
const self = this;
this.$v.registration_step${stepNumber}.touch()
if (this.$v.registration_step${stepNumber}.$error) {
this.$q.notify('Controleer aub de velden opnieuw');
return;
}
self.$refs.stepper.next();
},
Но это не работает. Как вы можете видеть, я хочу вызывать .touch() для динамической переменной в зависимости от того, на каком этапе пользователь находится в данный момент (поэтому он станет таким. $ V.registration_step1.touch(), если пользователь в данный момент находится на шаге 1.
Как бы вы это сделали?
попробуйте получить доступ к ключу другим способом:
this.$v['registration_step${stepNumber}'].touch()
this.$v['registration_step' + stepNumber].touch()
step${stepNumber}
; console.log (это $ v.registration [шаг].); const currentStep = this. $ v.registration [step]; currentStep.touch (); if (currentStep. $ error) {this. $ q.notify ('Controleer aub de velden opnieuw'); вернуть; } self. $ refs.stepper.next (); }, `Но все равно не повезло.
TypeError: this.$v.registration["".concat(...)].touch is not a function
примечанием: я реорганизовал объект регистрации, поэтому мой код теперь такой:validateStep(stepNumber) { const self = this; const step =
step $ {stepNumber}; console.log(step); this.$v.registration[
$ {step}].touch(); if (this.$v.registration[
$ {step}].$error) { this.$q.notify('Controleer aub de velden opnieuw'); return; } self.$refs.stepper.next(); },