ElementUi 读取excel文件后无法修改表单
第一次点开对话框,选择一个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.engAscription = 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)
})
},
有的时候elemenui确实会出现这种问题,你要么把值重新赋值下,要么不用elemenui的select等,手写下,但可以用elemenui的样式