解决了:
代码如下:
<input type="file" class="file"/>
<el-button type="primary" @click="readFile">导入文本</el-button>
`
readFile() {
let fileSelect = document.querySelector('input[type=file]').files[0]//找到文件上传的元素
let reader = new FileReader()
if (typeof FileReader === 'undefined') {
console.log('您的浏览器不支持FileReader接口')
return
}
reader.readAsText(fileSelect, 'gb2312')//注意读取中文的是用这个编码,不是utf-8
const _this = this
reader.onload = function() {
// console.log(reader.result)
_this.$nextTick(() => {
_this.voiceContent = reader.result
// console.log(_this.voiceContent)
})
}
console.log(reader)
}`
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…