返回Axios的问题

lsmepo6l  于 2022-11-05  发布在  iOS
关注(0)|答案(1)|浏览(107)

我在我的项目中使用Axios,我想导出axios函数,以便在我的vue文件中使用。
但是每当我使用它的时候,它总是说.then()是未定义的。我想我知道为什么,因为我在一个异步函数中返回了Axios。
但是我如何使用.then()来获取和使用vue文件中的响应。
我的vue代码:

  1. stopAll(){
  2. startmeetingApi.stop().then((res) => {
  3. this.transcript = res.data.transcript;
  4. });
  5. console.log(this.transcript);
  6. // this.$router.go();
  7. },

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

  1. stop(){
  2. recorder.stop().getMp3().then(([buffer, blob]) => {
  3. const file = new File(buffer, 'test.mp3', {
  4. type: blob.type,
  5. lastModified: Date.now()
  6. });
  7. const formData = new FormData();
  8. formData.append("data", file);
  9. return Axios.post("http://voice-app.test/api/v1/file", formData, {
  10. headers: {
  11. 'Authorization': `Bearer ${localStorage.getItem("Bearer")}`,
  12. }
  13. }).catch((e) => {
  14. console.error(e);
  15. })
  16. }).catch((e) => {
  17. console.error(e);
  18. })
  19. }

以下是我遇到的错误,以供参考:未捕获(在承诺中)TypeError:无法读取undefined的属性(阅读'then
多谢了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题