zoukankan      html  css  js  c++  java
  • 【上传 下载文件】

    上传:

    //angular
    <input type="file" (change)="fileChange($event)" placeholder="上传文件">
    
    //vue
    <input type="file"  @change="fileChange" placeholder="上传文件">
    fileChange(event) {
            let fileList = event.target.files;
            if (fileList.length > 0) {
                let file = fileList[0];
                let formData = new FormData();
                formData.append('uploadFile', file);        //你的post接口,formData发送            this.upgradeService.postDeviceFile(formData, (res) => {
                })
          
            }
        }
    

      下载:

     <a class="iconfont  icon-xiazai1" @click="downModule(list.id,list.name)" title="下载"></a>
    

      

        downModule(id,name){
          download(id).then(
              response => {
                let blob = new Blob([response.data], {
                  type: 'application/vnd.ms-excel'
                })
                let fileName = name + '.lua'
                if (window.navigator.msSaveOrOpenBlob) {
                  navigator.msSaveBlob(blob, fileName)
                } else {
                  var link = document.createElement('a')
                  link.href = window.URL.createObjectURL(blob)
                  link.download = fileName
                  link.click()
                  //释放内存
                  window.URL.revokeObjectURL(link.href)
                }
              },
              err => {
                reject(err)
              })
        },
    

      

  • 相关阅读:
    牛客(28)数组中出现次数超过一半的数字
    牛客(27)字符串的排列
    2、Spring Cloud和dubbo简介
    1、微服务简介
    12、Spring Boot监控
    11、Spring Boot热部署
    10、Spring Boot分布式
    9、Spring Boot安全
    8、Spring Boot任务
    7、Spring Boot检索
  • 原文地址:https://www.cnblogs.com/whblogs/p/14464060.html
Copyright © 2011-2022 走看看