[Vuejs]-Accessing dynamic template refs with vue3 and typescript

0👍

You could use typescript type casting and do something like

interface VueFormField extends Vue {
    validate: () => any
}

validate() {
    this.form.formFields.forEach((field) => {
    let key = "";
    if (field.configuration) {
      key = field.configuration.key;
    }
    console.log((this.$refs[key] as VueFormField).validate());
  });
}

You could also use the dynamic component vue feature to get a more elegant solution generating your forms, also using template refs like this

Leave a comment