'Getting dynamic $refs value in Vue2
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
Solution 1:[1]
Use a string key directly, with brackets:
this.$refs['qty' + index]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joseph Silber |
