• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Vue 게시판 vue ajax 요청시 아직 데이터 없어서 undefined 나오는 에러

vue ajax 요청시 아직 데이터 없어서 undefined 나오는 에러

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #22947

    rudgks
    참가자

    <template>
      <div style="padding: 10px">
        <h4>팔로워</h4>
        <input placeholder="?" />
        <div class="post-header">
          <div
            class="profile"
            :style="background-image:url(${ax[0].image})"
          ></div>
          <span class="profile-name"></span>
        </div>
      </div>
    </template>

    <script>
    import axios from "axios";

    export default {
      name: "mypage",

      data() {
        return {
          ax: [],
        };
      },

      created() {
        axios.get("/follower.json").then((e) => {
          this.ax = e.data;
          console.log(this.ax);
        });
      },
    };
    </script>

    <style>
    </style>

    마운티드로도 해봣는데 runtime-core.esm-bundler.js?5c40:6800 Uncaught TypeError: Cannot read properties of undefined (reading 'image') 오류뜨면서 화면안나오네요.. 뭐가 문제일까요..

     

    #22969

    codingapple
    키 마스터

    ajax 요청은 오래걸립니다 그 전에 html을 보여주려고 하기 때문에 그런 것이 아닐까요 

    이미지가 들어있는 부분을

    만약에 데이터가 있으면 보여달라고 v-if문 처리를 해봅시다

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠