vue3.0中ref动态绑定
2024-10-21 03:31:29
// 自己使用 <div v-for="item in ['lisi','wanger']" :key="item">
<test :ref="(el) => setGraphRef(el, item)" />
</div> const setGraphRef = (el, type) => {
if (el) {
itemRefs[type] = el;
}
}; // 调用
const targetRef = itemRefs[item];
if (targetRef) targetRef.testa();
// 官方的例子
<div v-for="item in list" :ref="setItemRef"></div> import { onBeforeUpdate, onUpdated } from "vue"; export default {
setup() {
let itemRefs = [];
const setItemRef = (el) => {
if (el) {
itemRefs.push(el);
}
};
onBeforeUpdate(() => {
itemRefs = [];
});
onUpdated(() => {
console.log(itemRefs);
});
return {
setItemRef,
};
},
};
最新文章
- Win 10 文件浏览器无法打开
- mapreduce性能提升2
- No.014 Longest Common Prefix
- OC使用inline替代宏
- BZOJ 3573 米特运输
- eclipse中英文切换--四种方式
- css3 content画出各种图形
- 解决larave-dompdf中文字体显示问题
- svn switch 的用法
- IOS 动画的两种方式
- 前端资讯周报 3.13 - 3.19: WebVR来了!以及如何优化scroll事件性能
- 浏览器css隐藏滚动条的方法!除了IE一般都支持
- JavaScript基础视频教程总结(111-120章)
- Python-HTML 最强标签分类
- (netty宝贵知识)
- [原创]K8飞刀20150720 新增Shellcode Loader支持多种格式
- Maven存储库
- 个人网站不输入www.直接domain.com访问不了,输入www.domain.com能访问
- Redis下载和安装
- Linux Namespace
热门文章
- DC-9靶场练习
- python操作MySQL数据库连接(pymysql)
- 使用docker中的MySQL
- A_A01_001 KEIL4-KEIL5软件安装
- Django TypeError at /login/ &#39;bool&#39; object is not callable
- S2-013 CVE-2013-1966
- C++Vector源码解析(侯捷STL)
- Stream中的常用方法_count-Stream中的常用方法_limit
- java helloworld demo
- .net core 阿里云接口之拷贝文件