Vue.js

Props로 받아온 값을 created()에서 사용하지 못할때

MDanderson 2023. 4. 25. 01:35

 

2023-04-25 01:30:43.794  WARN 68132 --- [nio-8888-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "undefined"]

 

vue에선 String으로 보내는데  자바에서는 Long값으로 받는게 문제라고한다.

그런데 다른 경우는 String으로 보내도 Long으로 잘 받아지는데???????????????

 

이 문제는 아마도 created() 훅이 호출되는 시점과 this.event 데이터의 초기화 시점 사이의 타이밍 이슈 때문일 것입니다. 첫 번째 접속 때 this.event.eventId가 아직 정의되지 않았기 때문에 undefined가 전달되는 것입니다. 그러나 이후 페이지에서 다른 이벤트로 이동할 때에는 this.event 데이터가 이미 설정되어 있어서 문제가 발생하지 않습니다.

 

이렇게 바꿔주면 해결된다 이러면 eventId가 Props로 받아와졌을때 watch 로 actions에서 axios가 작동을 하니까..!