执行addCompany但val没拿到,怎么能解决,别说放回调里面
handleButton =()=>{
var val
this.getImgIdByFileSaveList(arrImg).then((res)=>{
val =res
console.log('先执行',val)
})
this.addCompany(val)
}
addCompany = async (params)=>{
await axios.ajax({
url:api.addCompany,
method:"post",
data:params
}).then((res)=>{
console.log('后执行')
})
}
getImgIdByFileSaveList = async (val)=>{
return await new Promise((resolve)=>{
axios.ajax({
url:api.getImgIdByFileSaveList,
method:"post",
data:{
fileSaveList:val
}
}).then((res)=>{
resolve(res.data)
})
})
}
await
只能在async
函数中使用。建议先了解了用法再使用async