document.querySelector('.file').addEventListener('change', function(e) {
//1.可以通过this拿到这个file的DOM元素
console.log(this)
//1. e 函数事件参数对象中也有这个file的DOM元素对象。使用e.target也可以直接拿到
console.log(e.target)
//对开发人员屏蔽,所以直接 必须调用这个文件的DOM对象的files属性,返回一个数组
let files = e.target.files
console.log(files)
// console.log(files.item(0))
// console.log(files[0])
// 判断一手是否有文件
if (!files.length) return
// 上传文件 创建FormData
let formData = new FormData()
// upFile就是后台接收的key
formData.append('upFile', files[0], files[0].name)
// 将formdata发送到后台即可
// 我用的 axios.post('url', formData)
})

最新文章

  1. jvm 之结构与机制
  2. bash快捷建
  3. jQuery源代码学习之七—队列模块queue
  4. .NET生成word文档服务器配置常见问题
  5. 标签工作区(navtab)
  6. JS打开摄像头并截图上传
  7. SSE图像算法优化系列十:简单的一个肤色检测算法的SSE优化。
  8. _.contains is not a function
  9. ios video标签部分mp4文件无法播放的问题
  10. Python内置函数(8)——bool
  11. MyBatis学习日记(三):戏说MyBatis配置文件
  12. 自定义element-ui中的图标
  13. 【.NET 深呼吸】在 .net core app 中使用 Composition
  14. GBDT学习
  15. linux列出目录下所有目录
  16. 关于plot画图的原理
  17. (转)一次棘手的rootvg更换硬盘处理过程
  18. A1048
  19. POJ 2186 Popular Cows(强连通分量Kosaraju)
  20. VMWare安装Ubuntu及配置开发环境遇到的问题集

热门文章

  1. webpack核心用法,为什么要使用webpack
  2. 真·生产力「GitHub 热点速览」
  3. 【KAWAKO】在windows上用CMake和MinGW编译c++工程
  4. 题解 P1627 [CQOI2009] 中位数
  5. fastai fit_one_cycle AttributeError: 'function' object has no attribute 'parameters'
  6. pg高可用方案repmgr带witness搭建
  7. Vue props配置项(属性)
  8. java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘ (using password: YES)问题
  9. linux 操作命令大全
  10. How to Use Arrays and Vectors