fix timeout error

This commit is contained in:
afc163 2016-07-17 15:25:12 +08:00
parent ae3d009ff6
commit def3d60069
2 changed files with 5 additions and 2 deletions

View File

@ -14,12 +14,15 @@ export default class Article extends React.Component {
return; return;
} }
const checkImgUrl = 'http://alipay-rmsdeploy-dev-image.oss-cn-hangzhou-zmf.aliyuncs.com/rmsportal/JdVaTbZzPxEldUi.png'; const checkImgUrl = 'http://alipay-rmsdeploy-dev-image.oss-cn-hangzhou-zmf.aliyuncs.com/rmsportal/JdVaTbZzPxEldUi.png';
utils.ping(checkImgUrl, status => { this.pingTimer = utils.ping(checkImgUrl, status => {
if (status === 'responded') { if (status === 'responded') {
links.forEach(link => (link.style.display = 'block')); links.forEach(link => (link.style.display = 'block'));
} }
}); });
} }
componentWillUnmount() {
clearTimeout(this.pingTimer);
}
getArticle(article) { getArticle(article) {
const { content } = this.props; const { content } = this.props;
const { meta } = content; const { meta } = content;

View File

@ -49,5 +49,5 @@ export function ping(url, callback) {
img.onload = () => finish('responded'); img.onload = () => finish('responded');
img.onerror = () => finish('error'); img.onerror = () => finish('error');
img.src = url; img.src = url;
setTimeout(() => finish('timeout'), 1500); return setTimeout(() => finish('timeout'), 1500);
} }