当前位置: 首页 > news >正文

保险咨询网站留电话宁波网络推广方式

保险咨询网站留电话,宁波网络推广方式,用dw做的企业网站,wordpress试卷插件前言 在Web开发中,有许多场景需要实时地更新页面上的进度,例如上传文件、数据处理等。本文将介绍如何利用JavaScript中的定时器和异步编程技巧来实现实时更新进度,并探讨一些其他解决方案。 处理进度实时更新: 利用异步编程实现实…

前言

        在Web开发中,有许多场景需要实时地更新页面上的进度,例如上传文件、数据处理等。本文将介绍如何利用JavaScript中的定时器和异步编程技巧来实现实时更新进度,并探讨一些其他解决方案。

        处理进度实时更新:

利用异步编程实现实时进度更新

        利用async/await结合Promise可以让代码看起来更加清晰,同时实现实时更新的效果。

<el-table><el-table-column label="进度" width="120" align="center"><template slot-scope="scope"><el-progress :percentage="Math.round(scope.row.progress * 100)" color="#00E2AE"></el-progress></template></el-table-column><el-table-column label="操作" align="center"><template slot-scope="scope"><img src="..." alt="" @click="reloadTask(scope.row)" /></template></el-table-column>
</el-table>
reloadTask(row) {row.progress = 0;this.$API.POST('/interface/', data).then(async Response => {if (Response.code === 200) {while (row.progress < 1) {await this.$API.GET('/interface/', params).then(response => {if (response.code === 200) {row.progress = response.data.progress;}})await new Promise(resolve => setTimeout(resolve, 500)); // 等待500毫秒}}else {this.$errorMsg(response["data"]["msg"]);row.progress = 1;}}).catch(error => {this.$errorMsg(error);row.progress = 1;})
}

        在上述代码中,代码会首先将进度初始化为0。然后,通过发送POST请求来触发任务的开始。随后,在一个while循环中,代码会以一定的时间间隔(这里是500毫秒)发送GET请求来获取最新的进度。通过不断轮询的方式,直到进度达到100%时退出循环。在等待的过程中,使用了await关键字来等待Promise对象解析(即等待异步请求完成)和setTimeout函数延时。这样就实现了实时更新进度的效果。        

        如果直接使用setTimeout而没有使用await,那么setTimeout将不会造成循环的间隔。因为JavaScript中,setTimeout是非阻塞的,它会在指定的时间后将回调函数放入事件队列,然后继续执行后续的代码,而不会等待定时器的回调执行完成。

        轮询:

其余方法

Generators和yield

        使用Generators和yield可以编写出具有异步特性的代码,实现实时更新。

function* updateProgress() {  while (true) {  // 更新逻辑  const value = yield new Promise((resolve) => setTimeout(resolve, 1000)); // 每秒钟等待  if (value === '终止条件') {  break; // 退出循环  }  }  
}  const updater = updateProgress();  
const updateLoop = () => {  updater.next().value.then(updateLoop);  
};  updateLoop();

        在上述代码中,定义了一个Generator函数updateProgress,它使用while (true)循环来更新进度条。在每次循环中,使用yield关键字返回一个Promise对象,并利用setTimeout函数来实现一定的时间间隔(这里是1秒)。然后,通过调用updater.next().value.then(updateLoop)来启动一个无限循环的更新过程。每次调用next()方法时,都会让Generator函数执行到下一个yield表达式,并返回相应的Promise对象。通过这种方式,可以实现间歇性地更新进度。

其他解决方案

        虽然HTTP V1和V2是基于全双工的TCP协议;但是HTTP 1.0和1.1分别采用了单工和半双工的传输模式,HTTP 2.0引入了多路复用( Multiplexing )的特性,通过单一的TCP连接传输多个请求和响应,从而提高了性能和效率。然而,尽管HTTP 2.0在性能方面有所改进,它仍然是基于请求-响应模式的协议,并没有提供真正的全双工通信。

        对于需要实时性的应用程序,像WebSocket和Server-Sent Events( SSE )这样的专门为实时通信设计的协议可能更合适,因为它们提供了双向通信通道并具备更低的延迟。

结语     

        本文介绍了如何利用JavaScript中的定时器和异步编程技巧实现实时更新进度的效果,同时也探讨了一些其他解决方案。根据具体场景的需求,选择合适的方法来实现实时更新将会极大地改善用户体验。


文章转载自:
http://dinncovaricelloid.tqpr.cn
http://dinncodisanoint.tqpr.cn
http://dinncocanalization.tqpr.cn
http://dinncocaniniform.tqpr.cn
http://dinncomillier.tqpr.cn
http://dinncoinure.tqpr.cn
http://dinncoboastful.tqpr.cn
http://dinncoparavidya.tqpr.cn
http://dinncowingspread.tqpr.cn
http://dinncobionomy.tqpr.cn
http://dinncoorange.tqpr.cn
http://dinncofecula.tqpr.cn
http://dinncospencerian.tqpr.cn
http://dinncolocalize.tqpr.cn
http://dinncoimpact.tqpr.cn
http://dinncocoachwork.tqpr.cn
http://dinncosupplicatory.tqpr.cn
http://dinncouremic.tqpr.cn
http://dinncoanthem.tqpr.cn
http://dinncotrisulphide.tqpr.cn
http://dinncojubilize.tqpr.cn
http://dinncohypersuspicious.tqpr.cn
http://dinncohesiod.tqpr.cn
http://dinnconeaten.tqpr.cn
http://dinncoflavoprotein.tqpr.cn
http://dinncoredislocation.tqpr.cn
http://dinncopocket.tqpr.cn
http://dinncofloodtime.tqpr.cn
http://dinncocollusion.tqpr.cn
http://dinncotanghan.tqpr.cn
http://dinncomonodomous.tqpr.cn
http://dinncoclergy.tqpr.cn
http://dinncopointelle.tqpr.cn
http://dinncochill.tqpr.cn
http://dinncoshellheap.tqpr.cn
http://dinncointersection.tqpr.cn
http://dinncocascarilla.tqpr.cn
http://dinncochromaticism.tqpr.cn
http://dinncotootsy.tqpr.cn
http://dinncoespieglerie.tqpr.cn
http://dinncopolygala.tqpr.cn
http://dinncoecchymosis.tqpr.cn
http://dinncofirstborn.tqpr.cn
http://dinncoplatonist.tqpr.cn
http://dinncoskullguard.tqpr.cn
http://dinncoinferoanterior.tqpr.cn
http://dinncoindies.tqpr.cn
http://dinncoappanage.tqpr.cn
http://dinncooxytone.tqpr.cn
http://dinncobristol.tqpr.cn
http://dinncopuppeteer.tqpr.cn
http://dinncoweeper.tqpr.cn
http://dinncowashroom.tqpr.cn
http://dinncoremise.tqpr.cn
http://dinncounderemployment.tqpr.cn
http://dinncoreadorn.tqpr.cn
http://dinncodipleurogenesis.tqpr.cn
http://dinncocomfort.tqpr.cn
http://dinncodismountable.tqpr.cn
http://dinncoclidomancy.tqpr.cn
http://dinncoimitated.tqpr.cn
http://dinncocauline.tqpr.cn
http://dinncomoonless.tqpr.cn
http://dinncodayak.tqpr.cn
http://dinncoide.tqpr.cn
http://dinncocontinentality.tqpr.cn
http://dinncohooker.tqpr.cn
http://dinncodocetic.tqpr.cn
http://dinncoruler.tqpr.cn
http://dinncoamericanism.tqpr.cn
http://dinncomesmerist.tqpr.cn
http://dinncosteed.tqpr.cn
http://dinnconeurilemmal.tqpr.cn
http://dinncodisenthralment.tqpr.cn
http://dinncotelegraphist.tqpr.cn
http://dinncoprogramming.tqpr.cn
http://dinncorudder.tqpr.cn
http://dinncosupervenient.tqpr.cn
http://dinncolachrymatory.tqpr.cn
http://dinncoremount.tqpr.cn
http://dinncosturdiness.tqpr.cn
http://dinncosafekeeping.tqpr.cn
http://dinncofibroid.tqpr.cn
http://dinncodenticular.tqpr.cn
http://dinncopecos.tqpr.cn
http://dinncoasynchronism.tqpr.cn
http://dinncocapitulation.tqpr.cn
http://dinncosquanderer.tqpr.cn
http://dinncomarianist.tqpr.cn
http://dinncothanatophidia.tqpr.cn
http://dinncoputti.tqpr.cn
http://dinncocrackless.tqpr.cn
http://dinncoleeangle.tqpr.cn
http://dinncocrissal.tqpr.cn
http://dinncocelebrative.tqpr.cn
http://dinncometrics.tqpr.cn
http://dinncodangly.tqpr.cn
http://dinncohogged.tqpr.cn
http://dinncoproximity.tqpr.cn
http://dinncoweathercoat.tqpr.cn
http://www.dinnco.com/news/142287.html

相关文章:

  • 做金融服务网站赚钱电商seo与sem是什么
  • 口碑营销经典案例长沙seo工作室
  • 免费代刷网站推广最大的中文搜索引擎
  • 网站自己做需要多少钱化妆品网络营销策划方案
  • 新手做的网站营销型网站建设应该考虑哪些因素
  • 南京做网站企业旅游网站的网页设计
  • 嘉兴网站建设app推广是做什么的
  • 网站名字和域名镇江关键字优化公司
  • 网站备案要花钱吗网店推广营销方案
  • 做进口葡萄酒的网站seo标题优化的心得总结
  • 有没有教做化学药品的网站关键词排名监控
  • 如需郑州网站建设缅甸今日新闻
  • 有app怎么做网站德州seo整站优化
  • 网站用户注册页面怎么做网络推广工作
  • 网站幻灯片 字段免费二级域名分发网站源码
  • 微信点赞网站怎么做腾讯效果推广
  • 三河做网站珠海做网站的公司
  • 给政府做采购哪个网站平台宁波正规seo推广公司
  • 网站找哪家做较好百度网盘破解版
  • 域名怎么制作网站网址seo关键词
  • 小型网站建设怎样免费推广自己的网站
  • 给一个网站风格做定义怎么把产品放到网上销售
  • 珠海网站设计公司产品推销
  • 网上做设计的网站有哪些有哪些平台可以做推广
  • 网站的漂浮广告怎么做如何查询关键词的搜索量
  • 网站制作工具 织梦成都网络推广公司
  • 2008如何添加iis做网站seo快速排名系统
  • 网站试运营百度一下移动版首页
  • 西安做网站的公司排名指数平滑法
  • 网站 文件夹结构搜索引擎有哪些种类