一. 上传
1.formData
handleChange(params){
// console.log("开始上传")
this.loading = true;
let formData = new FormData();
formData.append("file", params.file); //把文件及其他参数加到formData里,:http-request是params.file,:on-change是file.raw
formData.append("code", this.form.code);
fetchUpload(formData) //调用上传接口
.then(res => {
this.$message({
showClose: true,
message: "上传成功",
type: "success"
});
this.imageUrl = res;
this.imageList.push( {
url: res
} );
this.type = params.file.type.split('/')[0] === 'image' ? 1 : 2;
})
.catch(res => {
this.$message({
showClose: true,
message: "上传失败",
type: "error"
});
})
.finally(() => {
this.loading = false;
// console.log("上传结束")
});
}
二. 下载
1.blob
handleDownload() {
let params = {
code : this.form.code,
startTime : this.form.createdTime ? this.form.createdTime[0] : '',
endTime : this.form.createdTime ? this.form.createdTime[1] : ''
}
this.$confirm("此操作将下载当前数据, 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
download(params)
.then((res) => {
const blob = new Blob([res.data], {
type: 'application/vnd.ms-excel' //xls
// type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' //xlxs
});
let filename = res.headers["content-disposition"].split("filename=").pop();
FileSaver.saveAs(blob, filename);
})
.catch((err) => {});
})
.catch((e) => {
this.$message({
type: "info",
message: "已取消下载",
});
});
}