我有一个包含标题、正文和用户 ID 的 API,我想在另一个 API 的帮助下打印用户名。那么我该怎么做呢?我在下面列出了这两个 API。
getUser(id) {
let userData = fetch(`https://jsonplaceholder.typicode.com/users/${id}`)
.then(response => response.json())
.then((responseJson) => {
return responseJson.name
})
.catch(error => console.log(error)) //to catch the errors if any
console.log(userData);
return userData;
};