2
我在vuejs中有一个用于文件上传的小组件(使用axios)。我试图从发出文件上传这样的回应:如何在vuejs发出respose之前等待axios响应
methods: {
...
upload(){
axios.put(URL).then(response => {
console.log('response', response)
this.$emit('uploaded', response)
}).catch(error => {
})
}
}
但在此代码,即使console.log()
响应显示了罚款,所述发送显示undefined
。我认为在响应准备好之前发出的是被调用的。
反正有异步/等待解决这个问题吗?
我觉得这是工作。我会尝试几次来确定,但我不明白你为什么需要try/catch? – hidar
try catch与.then和.catch类似,它就在那里,因此您知道您的操作是成功还是失败 – linasmnew