在vue中返回Axios的问题



我在项目中使用Axios,我想导出Axios函数,以便在我的vue文件中使用它。

但每当我使用它时,它总是说.then((是未定义的。我想我知道为什么,因为我在异步函数中返回Axios。

但是我如何使用.then((来获取和使用vue文件中的响应呢。

我的vue代码:

stopAll(){
startmeetingApi.stop().then((res) => {
this.transcript = res.data.transcript;
});
console.log(this.transcript);
// this.$router.go();
},

startmeetingApi.stop方法位于一个外部文件中:

stop(){
recorder.stop().getMp3().then(([buffer, blob]) => {
const file = new File(buffer, 'test.mp3', {
type: blob.type,
lastModified: Date.now()
});
const formData = new FormData();
formData.append("data", file);
return Axios.post("http://voice-app.test/api/v1/file", formData, {
headers: {
'Authorization': `Bearer ${localStorage.getItem("Bearer")}`,
}
}).catch((e) => {
console.error(e);
})
}).catch((e) => {
console.error(e);
})
}

作为参考,这是我得到的错误:未捕获(在承诺中(类型错误:无法读取未定义的属性(读取'然后

非常感谢。

我刚刚忘记归还录音机。stop…

谢谢大家!

最新更新