zoukankan      html  css  js  c++  java
  • axios上传excal方法

    方法一(适合传文件且带参数的方法)

    HTML内容
    <a href="javascript:;" class="select-file">
         <input type="file" @change="fileChange">
        选择文件
    </a>
    
    JS内容
    
    fileChange (e) {
          let file = e.target.files[0]
          this.newFile = file
          console.log(file)
          let formData = new FormData();
          formData.append("uploadFile", this.newFile);
          formData.append("remark", this.remark);  // 其它参数
          formData.append("name", this.name);  // 其它参数
        
            let data = await baseManage.checkStation(formData)
     },    

    方法二(适合只传文件不带参数的方法)

    HTML内容
    <a href="javascript:;" class="select-file">
         <input type="file" @change="fileChange">
        选择文件
    </a>
    
    JS内容
    
    fileChange (e) {
          let file = e.target.files[0]
          this.fileName = `${file.name.slice(0, file.name.lastIndexOf('.'))}_${new Date().getTime()}.xlsx`
          this.newFile = new File([file], this.fileName, { type: file.type });
    
        await axios({ method: "post", url:'http:xxxxx', data: this.newFile, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }  }).then((res) => {
            if (res.code === 0) {
              this.$message.success("上传完成")
            } else {
              this.$message.warning(res.msg)
            }
          }).finally(()=> this.state = '成功')
    
    
     }, 
  • 相关阅读:
    各种编译器
    C99特性
    动态内存分配
    MDK C++编程说明
    C++类的大小计算
    WPF DataGrid添加编号列
    WPF实现打印用户界面功能
    WPF DataGrid 导出Excel
    知识点总结
    Winfrom控件使用
  • 原文地址:https://www.cnblogs.com/chailuG/p/14519175.html
Copyright © 2011-2022 走看看