본문 바로가기

Front-End/Vue.js

axios response undefind 문제

호출 부분

const removeColList = await this.fn_originChk(indicesToRemove);
const indiColList = await this.selIndiColsList(removeColList);

메서드 부분

//품질 지표 컬럼을 참조하고 있는 컬럼 조회
    async selIndiColsList(data){

      const params = {
        tableNm: this.tableNm,
        colList: data
      };
      
      let api = '/ajax/getData.do';

      await axios.post(process.env.VUE_APP_API_URL + api, params)
        .then(response => {
          console.log("response.data : ",response.data.indiColList);
          return response.data.indiColList;
        })
        .catch(error => {
          console.log('error >> ' + error)
      })
    },

백날해도 indiColList 가 undefined가 뜬다.

//품질 지표 컬럼을 참조하고 있는 컬럼 조회
    async selIndiColsList(data) {
      const params = {
          tableNm: this.tableNm,
          colList: data
      };

      let api = '/ajax/getData.do';

      try {
          const response = await axios.post(process.env.VUE_APP_API_URL + api, params);
          console.log("response.data : ", response.data.indiColList);
          return response.data.indiColList; // 응답 데이터의 indiColList 반환
      } catch (error) {
          console.log('error >> ', error);
          return []; // 에러 발생 시 빈 배열 반환
      }
    }

이런식으로 response 객체가 const 로 뺀 후 return 하니까 잘 넘어감

 

제가 빠뜨린 부분이나 이유를 알고 계신다면 댓글 부탁드립니다..