Vue批量导入Excel
vue
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
项目地址:https://gitcode.com/gh_mirrors/vu/vue
·


代码
<el-upload
action="#"
:auto-upload="false"
:show-file-list="false"
accept=".xlsx"
:on-change="upLoadExcel"
>
<el-button icon="Upload" type="info"> 批量导入 </el-button>
</el-upload>
const upLoadExcel = (file) => {
// 文件上传前做一下判断
const type_ALLOWD = ['xlsx'];
const fileType = file.raw.name.substring(file.raw.name.lastIndexOf('.') + 1);
// 判断文件格式
if (type_ALLOWD.indexOf(fileType) === -1) {
ElMessage({
showClose: true,
message: "只能上传以'.xlsx'结尾的文件,请重新上传!",
type: 'error',
});
} else {
let formData = new FormData();
formData.append('file', file.raw);
//uploadData是上传文件的接口
//export function uploadData(param) {
// return request({
// url: 'xxxx',
// method: 'post',
// data: param,
// headers: { 'Content-Type': 'multipart/form-data;charset=utf-8' },//解码
// });
// }
uploadData(formData).then((res) => {
if (res.code == '0') {
state.fileUrl = res.data.fileInfo.fileUrl;
//uploadPBuildDataImport是将拿到的上传文件地址上传至后台的接口
//export function uploadPBuildDataImport(query) {
// return request({
// url: `xxxxx?fileUrl=${query}`,
// method: 'post',
// });
// }
uploadPBuildDataImport(state.fileUrl).then((res) => {
if (res.code == '0') {
ElMessage({
showClose: true,
message: '上传成功',
type: 'success',
});
} else {
ElMessage({
showClose: true,
message: res.msg,
type: 'error',
});
}
});
} else {
// 导入失败
ElMessage({
showClose: true,
message: '导入失败,请重试!',
type: 'error',
});
}
});
}
};
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:3 个月前 )
9e887079
[skip ci] 1 年前
73486cb5
* chore: fix link broken
Signed-off-by: snoppy <michaleli@foxmail.com>
* Update packages/template-compiler/README.md [skip ci]
---------
Signed-off-by: snoppy <michaleli@foxmail.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐



所有评论(0)