外观
外观
怡然
218字小于1分钟
问题解决异步
2025-06-10
相关信息
接手其他同事的代码,在async/await
中使用try/catch
调用接口,接口调用成功后dialog
的visible
为true
的操作不生效,导致dialog
无法显示,经排查,监听该visible
的值也监听不到任何变化,说明在try
当中对visible
的改变未生效。 async
和await
是基于Promise
的语法糖,使得异步代码看起来更像同步代码。
async handelQA(question) {
this.loading = true
this.tagLoading = true
const sendInput = {
question: question,
userId: String(store.state.user.userInfo.user.userId)
}
try{
const {code,data} = await handlerQAndA(sendInput)
// xxx...
if(code==200){
this.QAData = this.handleData(res.data)
this.visible=true // 不生效,监听不到变化
}
}catch(e){
// xxx
}
},
handelQA(question) {
this.loading = true
this.tagLoading = true
const sendInput = {
question: question,
userId: String(store.state.user.userInfo.user.userId)
}
handlerQAndA(sendInput)
.then((res) => {
if (res.code == 200) {
this.QAData = this.handleData(res.data)
this.QAVisible = true
}
})
.catch((e) => {
console.log(e)
})
.finally(() => {
this.loading = false
this.tagLoading = false
})
},