<input type="file" accept="image/*;capture=camera">
不加capture会打开两个
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | uploadImgClick = () => { const that = this const uploadInput = document.createElement( 'input' ) uploadInput.style.display = 'none' uploadInput.type = 'file' uploadInput.accept = 'image/*' // uploadInput.capture = "camera" uploadInput.addEventListener( 'change' , evt => { let file = evt.target.files[0] var reader = new FileReader() // 绑定load事件 // const { fileName, base64Str } = imageItem; reader.readAsDataURL( document.querySelector( 'input[type=file]' ).files[0] ) reader.onload = function (e) { that.setState({ loadingStatus: true }, () => { fetch( '/ui-api/aliyun/uploadBase64ImageSimple' , { credentials: 'include' , method: 'POST' , headers: { 'Content-type' : 'application/json' }, body: JSON.stringify({ fileName: file.name, base64Str: e.target.result }) }) .then(res => { that.setState({ loadingStatus: false }) return res.json() }) .then(res => { // 用完需要清除掉,要不会一直取第一个 document.body.removeChild(uploadInput) if (res.code === 0) { that.setState({ imgUrl: res.data.url }) } }) }) } }) document.body.appendChild(uploadInput) const evt = document.createEvent( 'MouseEvents' ) evt.initMouseEvent( 'click' , false , false ) uploadInput.dispatchEvent(evt) } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· [翻译] 为什么 Tracebit 用 C# 开发
· 腾讯ima接入deepseek-r1,借用别人脑子用用成真了~
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?
· 深度对比:PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
2017-07-15 IE8的兼容问题