RN-async await
// 定义一个异步函数
const asd = async () => {
// 使用 await 等待一个 Promise 解决
const result = await fetchData(); // fetchData() 返回一个 Promise
console.log(result); // 直接获取 Promise 解决的值
return result; // 相当于 return Promise.resolve(result)
};
// 调用异步函数
asd()
.then((data) => console.log('最终结果:', data))
.catch((error) => console.error('错误:', error));
浙公网安备 33010602011771号