We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const defaultHeader = { 'Accept': 'application/json', 'Content-Type': 'application/json' }; const delayPromise = (delay) => { // 默认3秒后没返回数据就是超时 return new Promise((resolve, reject) => { setTimeout(() => { reject({ status: 408, msg: '网络连接超时!' }); }, delay); }); }; const fetchPromise = (url) => { return new Promise((resolve, reject) => { fetch(url) .then((response) => response.json()) .then((res) => { console.log('res, res', res); resolve(res); }).catch(err => { console.log('err, err', err); reject(err); }) .done(); }); } const fetchData = (url, delay = 3000) => { return Promise.race([delayPromise(delay), fetchPromise(url)]); } export default fetchData;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: