function checkStatus(response) { return new Promise((resolve, reject) => { const json = response.json(); // [200,299] if (response.ok) { return json.then(resolve, reject); } if(response.status !== 200){ alert("接口请求失败!") } json.then(reject); }); } export default function fetch(input, init) { if (!init) { init = {}; } init.headers = { 'Content-Type': 'application/json', ...init.headers }; return window.fetch(`/${input}`, init).then(checkStatus); }