I'm working on a vue application.
I have dynamic ref
binding for input elements that accept quantity
Something like this -
:ref="'qty' + index"
When I log this.$refs
, I get all the refs. qty0, qty1, qty2 and so on.
My question is, how do I get the value of a particular input element using the ref?
I cannot hardcode this.$refs.qty0
as the index keeps changing.
I tried
let quantityRef = 'qty' + index;
console.log(index); // 0
console.log(quantityRef); // qty0
console.log(this.$refs.quantityRef); // undefined
Thanks in advance
Use a string key directly, with brackets:
this.$refs['qty' + index]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With