2017-09-16 7 views
0

해결 된 약속 개체 속성에 액세스하는 데 문제가 있습니다.해결 된 약속 개체 속성에 액세스

.then((response) => console.log(response.json()))

내가이 일을하여 응답 개체의 user 속성에 액세스하려고 해요 : 가져 오기 사용

, 나는 .then이 일이

.then((response) => console.log(response.json().user))

및 돌아 오는 중 undefined

이 작업을 수행하는 올바른 방법은 무엇입니까?

답변

3

response.json() 다른 약속을 반환합니다. 다른 .then() 콜백을 사용해야합니다.

fetch(...) 
    .then(response => response.json()) 
    .then(data => console.log(data.user)) 
+0

이 방법이 효과적입니다. 고맙습니다! –