<div>
<input type="file" class="file" name="file" @change="uploadBefore">
</div>
export default {
methods:{
//选择文件
uploadBefore(){
var formData = new FormData() // 声明一个FormData对象
this.formData = new window.FormData() // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
this.formData.append('file', document.querySelector('input[type=file]').files[0]) // 'userfile' 这个名字要和后台获取文件的名字一样;
let file = document.querySelector('input[type=file]').files[0]
console.log(this.fileName)
let fileName = file.name.substring(file.name.lastIndexOf(".")+1,file.name.length)
const fileType = fileName == 'xls'||fileName == 'xlsx'||fileName == 'ppt'||fileName == 'pptx'||fileName == 'doc'||fileName == 'docx'||fileName == 'txt'||fileName == 'pdf'||fileName == 'jpg'||fileName == 'gif'||fileName == 'jpeg'||fileName == 'png'||fileName == 'bmp'||fileName == 'mp3'||fileName == 'mp4';
// console.log(file)
// console.log(fileName)
// console.log(fileType)
if (!fileType) {
this.$message.error('上传文件格式不正确,请检查');
this.numberValidateForm.fileName = ""
}else{ this.numberValidateForm.fileName = file.name
}
},
// 保存,上传文件
submitForm() {
this.saveLoading = true
this.$http({
url: this.$store.state.domian+'/bbt-admin/courseware/upload/'+dynamicppt,
data: this.formData,
method: 'post',
headers: {
'Content-Type': 'multipart/form-data',
}
}).then((res => {
if (res.data.statusCode == 0) { this.$message({message:'操作成功!',type: 'success'})
this.dialogTableVisible = false
this.getFileList(1); }
this.saveLoading = false
console.log(res)
})
) });
},
} }

  

最新文章

  1. linux vps安装kloxo配置全部过程
  2. C++函数返回局部指针变量
  3. Python:if __name__ == &#39;__main__&#39;
  4. iOS之UI--指示器HUD的创建和设置
  5. Acdream1217 Cracking&#39; RSA(高斯消元)
  6. UVa 11426 (欧拉函数 GCD之和) GCD - Extreme (II)
  7. struts1面试题
  8. View的工作原理(一)——Measure
  9. [转载] 关于Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 的详解
  10. Images as x-axis labels
  11. Git &amp; github 使用指南
  12. 关于 pyspider Web预览界面太小的解决方法
  13. CMDB-(paramiko模块 -- 实现ssh连接)
  14. 【转】CentOS 7部署ASP.NET Core应用程序
  15. node 各模块及对应功能
  16. RESET MASTER和RESET SLAVE使用场景和说明【转】
  17. 深入理解$watch ,$apply 和 $digest --- 理解数据绑定过程——续
  18. 1692. [USACO07DEC] 队列变换【后缀数组+贪心】
  19. Controller层@PathVariable使用
  20. DevExpress 行事历(Scheduler)的常用属性、事件和方法

热门文章

  1. c++的各种类型转换方式
  2. nodejs 导出 exel文件 xlsx
  3. 20145302张薇 《网络对抗技术》 web基础
  4. 20145204《网络对抗》逆向及bof基础实践
  5. Effective TensorFlow Chapter 4: TensorFlow中的广播Broadcast机制【转】
  6. 从bios启动说起
  7. 第四章 消息摘要算法--SHA
  8. OI无关--关于侧边栏
  9. java反射基础
  10. java中常量接口及实现常量接口的利与弊