我目前通过调用异步函数并将其与.then()链接来处理我的承诺。但我希望有一种更易读的方法。
我目前的可行方法是:
const apiCall = async() => { const response = await axios.get("URL"); return response; } apiCall().then(res => { console.log(res.data); });
我希望我的代码看起来像:
const apiCall = () => { const response = axios.get("URL); return response; } const fetchData = async() => { const response = await apiCall(); return response.data; } console.log(fetchData());
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
如何