js检测资源是否存在
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)); },