使用async/await或Promise的then()方法来处理Promise对象并获取实际数据。
示例代码:
使用async/await:
async function fetchData() { const response = await fetch('https://api.example.com/data'); const data = await response.json(); console.log(data); }
使用Promise的then()方法:
fetch('https://api.example.com/data') .then(response => response.json()) .then(data => console.log(data));