Home > OS >  Vue 3, Typescript: How do I pass parameters to template refs?
Vue 3, Typescript: How do I pass parameters to template refs?

Time:10-19

From Template

<input v-for="i in 5" :key="i" :ref="refHandler($el, i)" />

From setup()

const refHandler = (el: HTMLInputElement, i: number) => {
  if (el) inputs.value[i] = el;
};

el seems to show as null. How do I pass parameters to template refs?

CodePudding user response:

Your ref binding in the template should be a function that declares its argument as $el for it to be defined in your callback:

                                                 
  • Related