1.上传代码
<el-upload :action="'/xxx'" :on-success="handleSuccess" :on-change="handleChangePic" accept=".xls,.xlsx">
<el-button size="small" type="primary">上传资料</el-button>
</el-upload>
methods: {
handleSuccess(res, file) {
// action 上传时的回调
this.ifload = false;
if (res.code === 200) {
this.$message.success('文件导入成功');
this.fileList = [];
this.handleClose();
} else {
this.$message.error(res.msg || '文件导入失败,稍后重试');
}
}
}
2.下载代码
<el-button type="primary" size="small" @click="download">下载模板</el-button>
methods: {
download() {
const a = document.createElement('a');
a.target = '_blank';
a.href = `/xxx`;
document.body.appendChild(a);
a.click();
},
}