elementUI第一次打开对话框,读取excel文件后,无法修改表单内容;关掉对话框重新打开,再次读取excel文件后,可以正常修改表单内容;或者是第一次点开对话框后,先修改了表单内容,再进行文件读取,也可以正常修改表单内容;
相关代码:
addUpload(e){
const types = e.name.split('.')[1]
const fileType = ['xlsx', 'xls'].some(item => item === types)
if (!fileType) {
this.$message('格式错误!请重新选择')
return
}
this.file2Xce(e).then(tabJson => {
if (tabJson && tabJson.length > 0) {
this.form.pjName = tabJson[0][0].项目名称
this.form.pjCode = tabJson[0][0].项目编码
this.form.pjAscription = tabJson[0][0].项目属性
this.form.engName = tabJson[0][0].工程名称
}
})
},
file2Xce(file) {
return new Promise(function(resolve, reject) {
const reader = new FileReader()
const XLSX = require('xlsx');
reader.onload = function(e) {
const data = e.target.result
this.wb = XLSX.read(data, {
type: 'binary'
})
const result = []
this.wb.SheetNames.forEach((sheetName) => {
if( sheetName == '工程信息' ){
result.push(XLSX.utils.sheet_to_json(this.wb.Sheets[sheetName]))
}
})
resolve(result)
}
reader.readAsBinaryString(file.raw)
})
},
看下控制台 有没有报错
文件上传方法读取错误
<el-input
v-model="desc"
type="textarea"
@input="change($event)"
/>
change(e) {
this.$forceUpdate()
},
加上this.$forceUpdate()这句试试