html中:
<div :ref="`Ref${index}`"></div>
script中:
import { getCurrentInstance } from "vue";
const ctx = getCurrentInstance();
需要使用动态ref的函数中:
ctx.refs[`Ref${index}`].function();
Vue3.0中如何动态设置ref
最新推荐文章于 2025-09-25 13:39:33 发布
本文介绍了在Vue中如何使用动态ref属性绑定元素,并在script中通过getCurrentInstance获取实例来调用元素上的函数。示例展示了在html中定义动态ref如`Ref${index}
8109

被折叠的 条评论
为什么被折叠?



