报错:Unexpected reserved word 'await'
async handleDelete() {
let folderFilesIds = [1, 2]
this.$confirm('此操作将永久删除文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
await this.confirmHandleFiles(folderFilesIds)
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
修改为:
handleDelete() {
let folderFilesIds = [1, 2]
this.$confirm('此操作将永久删除文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
await this.confirmHandleFiles(folderFilesIds)
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
之前报错Unexpected reserved word 'await',是因为错把async放到handleDelete上,这里async和await是成对出现的,所以应该放在匿名函数的位置,加async的函数会被await阻塞,await会跳出async让出线程,所以说学一个东西是一回事,会用一个东西是另外一回事。。自勉下