admin管理员组文章数量:1243198
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
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
Share Improve this question edited Mar 16, 2022 at 12:55 Penny Liu 17.4k5 gold badges86 silver badges108 bronze badges asked Jan 26, 2018 at 0:54 VishwasVishwas 1,4988 gold badges22 silver badges34 bronze badges 1- Thanks, this helped me to find the doc. Just sharing this back for others. ponents-edge-cases – marlo Commented Oct 1, 2020 at 1:57
1 Answer
Reset to default 16Use a string key directly, with brackets:
this.$refs['qty' + index]
本文标签: javascriptGetting dynamic refs value in Vue2Stack Overflow
版权声明:本文标题:javascript - Getting dynamic $refs value in Vue2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740125441a2228766.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论