<el-upload
ref="upload"
action="https://jsonplaceholder.typicode.com/posts/"
:on-change="readExcel"
>
转换数组
</el-upload>
readExcel(file) {
var reader = new FileReader()
reader.readAsBinaryString(file.raw)
reader.onload = (e) => {
const data = e.target.result
const wb = XLSX.read(data, { type: 'binary' })
const wsname = wb.SheetNames[0]
const ws = wb.Sheets[wsname]
var result = XLSX.utils.sheet_to_json(ws, { header: 1 })
let arr = []
result.forEach(item =>{
let obj = {
title: item[0],
price: item[1],
id: item[2],
info: item[3],
img: item[4]
}
arr.push(obj)
})
console.log(JSON.stringify(arr))
}
}
}