导入:
// 导入 const importExcel = async (file: any) => { let formData = new FormData(); //声明一个FormDate对象 formData.append("file", file.raw); //把文件信息放入对象中 //调用后台导入的接口 importExcelAccount(formData).then(res => { if (res && res.code === 0) { ElMessage.success('导入成功!') getList() }else { ElMessage.error('导入失败!请稍后重试') } }) }
导出:
// 导出 const exportExcel = () => { axios({ method: 'get', url: 'api/company-server/office/finance/account/export', // 请求地址 responseType: 'blob', // 表明返回服务器返回的数据类型 headers: { "Content-Type": "application/json, text/plain, */*", Authorization: localStorage.getItem('token') as string, } }).then( (res: any) => { if (res.code) { ElMessage.warning(res.message); return } console.log(res) exportData('账户信息.xlsx', res.data) }) }
标签:res,formData,导出,导入,file,vue3,ElMessage From: https://www.cnblogs.com/alannero/p/17772977.html