取自VueJs组件(版本:2,class-style-component):
<v-container>
<v-row
v-for="(item, index) in shortcodes"
:key="index"
>
<v-col>
Замена №{{ index }}([__{{ index }}__])
<edit-select-dropdown-options-single
:ref="`editSelectDropdownOptionsSingle${index}`"
:value="item.options"
@select-option="setAnswer(index, $event)"
@remove-option="removeOption(item.options, $event)"
/>
</v-col>
</v-row>
</v-container>
动态就形成了ref。接下来,我需要参考这个ref:
this
.$refs[`editSelectDropdownOptionsSingle${replacement.shortcode_key}`}[0]
.someMethod(someArgs);
的文档refs。
我如何通过这个键来描述有一个数组,每个元素都有一个可用的方法someMethod?
好吧,如果以质朴的方式,那么就像这样。
在代码中:
在没有干扰器的情况下达到了预期的结果 (
eslint-disable-next-line,@ts-ignore)。也许我不明白,但出于某种原因,如果没有这些检查, TSC无法理解
$refs数组可以包含什么,我可以在索引 0 处访问该数组,并且该元素将EditSelectDropdownOptionsSingle是继承自的类的实例,Vue并且是一个组件。