页面部分
<el-upload
class="upload-demo"
action="https://jsonplaceholder.typicode.com/posts/"
:on-success="handleChange"
accept=".txt"
:file-list="fileList">//accept=".txt" 只允许上传txt文件 :on-success上传成功再读取数据
<el-button size="small" type="primary">上传</el-button>
</el-upload>
js部分
handleChange(response,file, fileList) {
let reader=new FileReader();
reader.readAsText(file.raw,'UTF-8')//读取,转换字符编码
reader.onload=function(e){
let val=e.target.result;//获取数据
let rtulist=val.split("\r\n")
console.log('rtulist:>> ', rtulist);
}
}