当前位置:网站首页>监听拖拽事件,第一次拖拽得不到上传的文件内容,第二次以后就能正常得到上传的文件内容
监听拖拽事件,第一次拖拽得不到上传的文件内容,第二次以后就能正常得到上传的文件内容
2022-07-16 13:39:00 【weixin_46787337】
bug描述:
监听拖拽事件,第一次拖拽得不到上传的文件内容,第二次以后就能正常得到上传的文件内容
错误代码示例
//React
<input type="file" onDrop={(e: React.DragEvent<HTMLInputElement>) => newFile(e)} />
const newFile = (e: React.DragEvent<HTMLInputElement>) => {
const el = e.target as HTMLInputElement;
console.log(el.files); //这里第一次上传并未得到上传的内容
if (el.files?.[0]) {
(transImg.fileToUrl(el.files[0]) as Promise<string>).then((res: string) => {
console.log(res);
});
}
};
正确代码
错误原因,api调用错误
//React
<input type="file" onDrop={(e: React.DragEvent<HTMLInputElement>) => newFile(e)} />
const newFile = (e: React.DragEvent<HTMLInputElement>) => {
const fileBlob = e.dataTransfer.files[0]; //应当使用这个接口
(transImg.fileToUrl(fileBlob) as Promise<string>).then((res: string) => {
console.log(res);
});
};
边栏推荐
猜你喜欢

Huawei image xmage: seek all the images in the world, and finally see the Bodhi Heart

Quick completion guide of manipulator (zero five): resources related to manipulator

老板想要的简单方案 vs. 程序员理解的需求 | 漫画

module ‘sklearn.datasets‘ has no attribute ‘fetch_mldata‘

用NavicatPremium导出数据

Question bank and answers of Shandong Provincial Safety Officer C certificate examination in 2022

Unity game file is large, how to reduce the game file

10个第一、2个第二,达摩院NLP团队在SemEval 2022的夺冠之旅

20220715 国内Conda不fq安装Pytorch最新版本的方法

2022年P气瓶充装考试试题及模拟考试
随机推荐
The art of code annotation. Does excellent code really need no annotation?
ECCV 2022 | 适用于分类,检测,分割的生成式知识蒸馏开源
用NavicatPremium导出数据
才22岁!这位“00后”博士拟任职985高校!
The web crawler crawls the titles and contents of all chapters of the romance of the Three Kingdoms (beautifulsoup analysis)
准确率100%,阿里商旅账单系统架构设计实践
The simple solution the boss wants vs. the needs the programmer understands | cartoon
Question bank and answers of Shandong Provincial Safety Officer C certificate examination in 2022
module ‘sklearn. datasets‘ has no attribute ‘fetch_ mldata‘
一次有趣(想打断同事腿)的键盘BUG调试经历
Robotics XM430-W350 云台电机使用记录
S7-200SMART案例分析——运动控制编程(二)
树莓派利用OpenCV的图像跟踪、人脸识别等
Lime of Py: a detailed introduction to the introduction, installation and use of the lime Library
Error ora-01017 is reported after RMAN recovers
Log4j log configuration
C 语言入门(七)
ctf-pikachu-sql
【开发教程7】疯壳·开源蓝牙智能健康手表-充电
使用plt.savefig()方法保存绘图时出现图片全白或全黑的问题