Fetch API比XMLHttpRequest确实好用多了,链式调用看着清爽。但有个坑,网络错误才reject,像404这种还得手动检查response.ok,Axios直接抛错就省心。
fetch('/api/data').then(res => {
if (!res.ok) throw Error(res.statusText);
return res.json();
})
登录/注册