vue 中给element-ui组件事件添加自定义参数


原因:

  有时同一个页面会多次使用组件, 为了区分从组件中拿到的数据,一般会给事件中添加参数用于区分

 

试例:

  下面看两个上传文件均用到 el-upload 组件, 在on-success事件中拿到数据后需要区分上传的是哪个文件

 

 错误的解决方案: 

1  :on-success="handleAvatarSuccess(1)"
2   //文件上传
3   handleAvatarSuccess(d:number,res: any, file: any,) {
4     console.log(d); // 1
5     console.log(res); // undefined
6     console.log(file); // undefined
7   }

会发现拿不到 res, file数据, 只能拿到自定义的参数

 

正确的解决方案:

1 :on-success="(response, file, fileList)=>handleAvatarSuccess(response, file, fileList,1)"
2   //文件上传
3   handleAvatarSuccess(res: any, file: any, fileList: any, d: number,) {  
4     console.log(res); // {...}
5     console.log(file); // {...}
6     console.log(d); // 1
7   }

 

分享一刻:

苹果营销页中几个有趣的交互动画


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM