vue3 模板下载,导入,导出

模板下载

//定义模板下载的方法(本地存放的模板路径有差异‘’./template/MaintenanceTemplate.xlsx

const templateDownloadFunction = () => {

    window.location.href = `./template/MaintenanceTemplate.xlsx?t=${new Date().getTime()}`;

};

导入

*与后端配合,后端提供导入接口

                     <el-upload ref="fileUpload" class="upload-demo"
                        action="/service/deviceMaintainTemplate/importCheckTemplateList" :show-file-list="false"
                        :on-success="uploadSuccess" :on-change="handleChange">
                        <!--  accept=".zip" -->
                        <el-button :icon="FolderAdd" color="#0542A8" class="resetting">
                            导入
                        </el-button>
                    </el-upload>




// 导入按钮
const handleChange = () => {
    console.log('handleChange---------')
}

//导入成功
const uploadSuccess = (file) => {
    if (file.code === 500) {
        ElMessage({
            showClose: true,
            message: '导入失败',
            type: "error"
        });
    } else {
        ElMessage({
            showClose: true,
            message: '导入成功',
            type: "success",
            duration: 2000,
        });
        getModelsFunction()
    }
}

导出

*与后端配合,后端提供导出接口

定义一个按钮

<el-button type="primary" @click="exportExcelFunction" class="resetting"

><el-icon class="reset-icon">

                            <Document />

                        </el-icon>导出</el-button>


// 导出
const exportExcelFunction = () => {
    window.open("/service/deviceVulcanizationErrorLog/export?deviceCode=" + topForm.deviceCode + '&' + 'deviceId=' + topForm.deviceId + '&' + 'deviceName=' + topForm.deviceName + '&' + 'errorMsg=' + topForm.errorMsg, "_blank");
}

*注:window.open("/service/deviceVulcanizationErrorLog/export?deviceCode=" + topForm.deviceCode+...., "_blank"); 接口前面的的"/"千万不能少/(ㄒoㄒ)/~~

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值