我正在开发一个 vue 应用程序。
我对接受数量的输入元素进行了动态 ref
绑定(bind)
像这样的 -
:ref="'qty' + index"
当我记录 this.$refs
时,我得到了所有的引用。 qty0、qty1、qty2 等等。
我的问题是,如何使用 ref 获取特定输入元素的值?
我不能对 this.$refs.qty0
进行硬编码,因为索引不断变化。
我试过了
let quantityRef = 'qty' + index;
console.log(index); // 0
console.log(quantityRef); // qty0
console.log(this.$refs.quantityRef); // undefined
提前致谢
最佳答案
直接使用字符串键,带括号:
this.$refs['qty' + index]
关于javascript - 在 Vue2 中获取动态 $refs 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48454317/