vue에서 Axios를 반환하는 문제

프로젝트에서 Axios를 사용하고 있는데 vue 파일에서 사용할 수 있도록 Axios 함수를 내보내고 싶습니다.

그러나 사용할 때마다 .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);
})
} 

참고로, 이것은 제가 받은 오류입니다: Uncaught (약속하지 않음)TypeError: 정의되지 않은 속성을 읽을 수 없습니다.

대단히 고맙습니다.



질문에 대한 답변