报错代码
uploadF () {
console.log('上传' + this.files)
if (this.fileName == '') {
this.$message.warning('请选择要上传的文件!')
return false
}
const fileFormData = new FormData()
fileFormData.append('file', this.files)// filename是键,file是值,就是要传的文件,test.zip是要传的文件名
const requestConfig = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
const { data } = this.$http.post('/sys/file/upload' + fileFormData).then((res) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refresh-list', true)
}
})
} else {
this.$message.error(data.msg)
}
})
}
报了一个很小众的错误,查了很多博客,找到类似的报错。
Uncaught TypeError: Cannot read property ‘then‘ of undefined
我的报错
Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'then')"
方法一:说是箭头函数需要添加return
,但是对我的代码来说似乎不太试用,随便加了一个地方不管用,评论区有解决方法。
方法二:我突发奇想在方法前加了关键字async
,然后报错消失了,不知道原理,所以先记录一下,查了查文档有如下介绍:
async function foo() {
await 1;
}
等价于
function foo() {
return Promise.resolve(1).then(() => undefined);
}
在 await 表达式之后的代码可以被认为是存在在链式调用的 then 回调中,多个 await 表达式都将加入链式调用的 then
回调中,返回值将作为最后一个 then 回调的返回值。