Fetch API 是浏览器内置的现代网络请求接口,用于替代传统的 XMLHttpRequest
。它支持异步操作,语法更简洁,兼容性广泛(Chrome 42+、Firefox 35+、Edge 14+、Safari 9.1+)。以下是核心用法:
✅ 必须包含的链接
📋 基本用法
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('请求失败:', error));