首先呢,我的需求是用Excel表做数据导入,前端传入文件,后端拿到文件解析,然后插入数据库,由于对vue不熟悉,踩了很多的坑,最后还是做完了,这里分享一下我踩过的坑。
直接贴代码吧:
<!--文件导入-->
<template>
<div>
<el-upload
class="filter-item"
name="file"
action="string"
:on-error="uploadFalse"
:on-success="uploadSuccess"
:before-upload="beforeAvatarUpload"
:limit="1"
ref="upload"
accept=".xlsx,.xls"
:show-file-list="false"
:file-list="fileList"
:http-request="uploadFile"
>
<el-button style="margin-left: 10px;" icon="el-icon-edit" type="primary" v-has-perm="">商品上架</el-button>
</el-upload