Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- VUE
- 리액트
- 자바
- forNmae()
- 컴포넌트 주도
- redux
- 리덕스 공식문서
- 자료구조
- paraller
- 커스텀 로그인
- 애그리거트
- react
- vue.js
- ACCESS_REFUSED
- $emit()
- 오라클
- rabbitmq 에러
- EBS
- 공식문서
- .getClass()
- exiting abnormally
- 네임드 뷰
- 리덕스
- 도커빌드
- quert
- REDIS
- AWS
- Express
- Java Reflextion API
- 오라클 병렬처리
Archives
- Today
- Total
개발정리
[트러블 슈팅] Cannot read properties of undefined (reading 'userId') 본문
개발/중거거래사이트 클론
[트러블 슈팅] Cannot read properties of undefined (reading 'userId')
coffee. 2024. 2. 23. 15:03axios로 json을 받아와서 v-text로 받아온 값을 출력하는 데 생긴 문제입니다.
<template>
<div class="box">
<div class="images">
<div v-for="(photo,index) in item.photos" :key="index">
<img :src="`http://localhost:8080/images/${photo}`" class="image" />
</div>
</div>
<hr/>
<div class="profile">
<div class="user">
<div class="photo" >
<img :src="`http://localhost:8080/images/${item?.publisher?.profile}`" />
</div>
<div>
<span> {{ item.publisher.userId }} </span>
</div>
</div>
<div>
</div>
</div>
<hr/>
<div>
<h2>{{ item.title }}</h2>
<h3>{{ item.price }}</h3>
<p>
{{ item.content }}
</p>
</div>
</div>
</template>
<script>
export default{
data(){
return{
item:{},
user:{}
}
},
mounted(){
this.$axios.get(`http://localhost:8080/item/${this.$router.currentRoute._value.params.id}`)
.then((response)=>{
this.item=response.data;
console.log(this.item.publisher.userId);
});
},
}
</script>
제 생각에는 mount단계에서 item.publisher 라는 배열의 값이 undefined가 되면서 예외를 발생시키는 것이 원인입니다.
해결
해결책에는 두가지가 있습니다.
첫번째
data(){
return{
item:{
publisher:{
userId:""
}
},
user:{}
}
},
사용하고자 하는 배열의 원소를 직접 지정하는 것 입니다.
두번째
<span> {{ item?.publisher?.userId }} </span>
참조
'개발 > 중거거래사이트 클론' 카테고리의 다른 글
[트러블 슈팅] sockJs /info 요청 404 error (0) | 2024.03.03 |
---|---|
[트러블 슈팅]-라우터 params undefined 문제 (0) | 2024.02.20 |
[트러블 슈팅] jpa 양방향 매핑 조회시 stackoverflow 문제 (0) | 2024.02.18 |
[트러블 슈팅] vue.js axios 인터셉터 설정 (0) | 2024.02.16 |
[트러블 슈팅]로그인시 로그아웃으로 변경 (0) | 2024.02.05 |