html
<el-upload
class="base"
ref="upload"
action=""
accept=".csv"
:before-upload="beforeFileUpload"
:on-change="handleFileUploaderChange"
:auto-upload="false"
:show-file-list="false"
>
<el-button
class="base"
size="small"
type="primary"
>上传文件</el-button>
</el-upload>
方法
handleFileUploaderChange (file) {
let testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
if (testmsg !== 'csv') {
this.$message.error(this.$t('certifivateNo.formatError'))
return
}
let reader = new FileReader()
if (file) {
reader.readAsDataURL(file.raw)
}
reader.onload = () => {
//执行的方法
}
}