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 = '成功')
    
    
     }, 
  • 相关阅读:
    淘宝技术架构演进之路
    单点登录
    [c++11] ——条件变量(Condition Variable)
    std::lock_guard unique_lock
    C++中push_back和emplace_back的区别
    C++11 CAS无锁函数compare_exchange_weak的使用
    C++11新特性之 rvalue Reference(右值引用)
    C++ auto和decltype的区别
    ovs contrack
    周总结03
  • 原文地址:https://www.cnblogs.com/chailuG/p/14519175.html
Copyright © 2011-2022 走看看