• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

async await 관련

20.05.30 19:14 작성 조회수 475

1

    async submitForm() {
      var msgAlert = '';

      if (this.crud == 'D') {
        msgAlert = `삭제하시겠습니까?`;
      }
      if (this.crud == 'C') {
        msgAlert = `입력 또는 수정하시겠습니까?`;
      }
      this.$confirm(msgAlert'확인').then(() => {
       async function basic() {
          const { exercises } = await saveRet(userData);
          return exercises;
        }

        var data = {};
        async () => {
           data = await basic();
          //data = await saveRet(userData);
        };

        alert(JSON.stringify(data));
}
},
질문 : confirm 안에 await를 사용하려합니다.
saveRet가 await 되지 않고 alert 메세지가 호출 됩니다.
부탁드립니다.

답변 1

답변을 작성해보세요.

0

안녕하세요 crowd614님, 콜백 함수 안에서 async await를 사용하시려면 아래 구조를 활용하시면 됩니다 :)

then(async () => {

  await sth();

})

강의 수강해주셔서 감사합니다! :)