我正在使用以下功能从pokemon api获取数据(结果):
const [data, setData] = useState({ results: []})
useEffect(() => {
const fetchData = async () => {
const response = await api.get('/pokemon');
setData(response.data);
};
fetchData();
}, []);
我的API函数:
const api = axios.create({
baseURL: 'https://pokeapi.co/api/v2'
});
这是我的回应
{
"count": 964,
"next": "https://pokeapi.co/api/v2/pokemon?offset=20&limit=20",
"previous": null,
//data that I need to use
"results": [
{
"name": "bulbasaur",
"url": "https://pokeapi.co/api/v2/pokemon/1/"
//the get request in the URL above can work both with name or number in pokedex.
},
//the list goes on till the 20th pokemon.
]
如何从results数组中对象内部的URL执行获取请求?