Vue.js - this.$refs.key returns an empty array or undefined instead of element
I strongly suggest considering these 2 good practices first:
- https://vuejs.github.io/eslint-plugin-vue/rules/no-use-v-if-with-v-for.html
- https://vuejs.github.io/eslint-plugin-vue/rules/require-v-for-key.html
Once that's taken care of, I'd suggest adding an index
to your v-for
and adding the :ref
to the individual buttons so you can find each one of them in a function.
Working with array items via ref
is rather well described here: this.$refs[("p" + index)].focus is not a function
You should be able to apply focus to the first button using something like this.$refs[
button${index}][0].focus();