【上传 下载文件】
上传:
//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) }) },