this.getPicture(() => { console.log(‘成功’) },url); // 获取图片 getPicture(conBack,url) { let that = this; // 使用示例 this.checkResource(url).then(exists => { if (exists) { conBack() } else { if(that.timerPic) { clearTimeout(that.timerPic) that.timerPic = null } that.timerPic = setTimeout(() => { that.getPicture(conBack,url) },5000) } }); }, checkResource(url) { return fetch(url, { method: 'HEAD' }) .then(response => response.ok) .catch(error => console.error('Resource check failed:', error)); },
标签:timerPic,exists,url,检测,js,getPicture,conBack,error,资源 From: https://www.cnblogs.com/heibaiqi/p/18234699