1

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?

2

1 Answer 1

1

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

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

demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.