在动态变量上调用js函数

时间:2019-01-10 16:24:14

标签: javascript

我想做的是这样:

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()(如果用户当前处于步骤1,则它将变为this。$ v.registration_step1.touch()。< / p>

您将如何做?

2 个答案:

答案 0 :(得分:2)

尝试以另一种方式访问​​密钥:

this.$v[`registration_step${stepNumber}`].touch()

答案 1 :(得分:-1)

this.$v['registration_step' + stepNumber].touch()
相关问题