ant design 上传(a-upload)excel

本文介绍了使用Ant Design的a-upload组件实现Excel上传的功能,详细展示了代码实现过程,欢迎读者提出建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近老是有导入excel的功能,现在有空就来整理一下,欢迎大家提意见。
直接上代码:

 <a-upload style="display: inline-block;"
                :accept="UPLOAD_FILE_SUFFIX"
                name="file"
                :multiple="false"
                :fileList= fileList
                :beforeUpload="beforeUpload"
                @change="handleChange()"
                >
                <a-icon :component="importIcon" style="margin-top:5px;" />导入
              </a-upload>
			  
/**
     * 上传文件前的回调,只允许上传word或者pdf格式的文件
     */
    beforeUpload(file){
		//文件类型判断
			if( file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || file.type == "application/vnd.ms-excel"){
				//只允许上传excel格式的文件
        this.fileTypeBool = true;
        let formData = new FormData();
        formData.append('file', file);
		//请求接口
        readPendingExcel(formData).then((res) => {

        }).catch(err => {
            this.getMaterialList(err.data);
            this.$message.success("导入成功");
        });

	}else{
		this.$message.error('请选择表格类型文件!');
		this.fileTypeBool = false;
	}
	//文件大小判断
	//const isLt2M = file.size / 1024 / 1024 <= 10
	 //if (!isLt2M) {
	//	this.$message.error('文件大小不超过10M!');
	//	this.fileSizeBool = false;
	// }else{
	//	this.fileSizeBool = true;
	 //}
    },
	 getMaterialList(list) {
        let arr = list.map(item => {
          return {
            singleProjectId: this.record.id,
            name: item["name"],
            sex: item["sex"],
            age: item["age"],
            unit: item["unit"],//单位
            number: item["number"],//数量
            status: item["status"] //数据是否正确状态
          }
        });
        
        this.tableData = arr;//渲染表格数据
      },

一顿乱操作,就出来想要的结果了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值