1、安装xlsx表格解析插件
cnpm i xlsx -s
2、引入表格解析插件:
import * as XLSX from 'xlsx'
3、封装文件二进制处理方法
utils.js
//【将文件类型转换成二进制】传入一个文件类型的数据,返回一个二进制数据
export function readFile(file){
return new Promise(resolve =>{
const reader = new FileReader()
reader.readAsBinaryString(file)
reader.onload = ev => {
resolve(ev.target.result)
}
})
};
4、vue3代码
<template>
<el-upload
v-model:file-list="fileList"
class="upload-demo"
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
multiple
:on-success="handsuccess"
>
<el-button type="primary">Click to upload</el-button>
</el-upload>
</template>
<script lang=