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

织梦网站模板如何安装教程视频教程最近国际新闻大事

织梦网站模板如何安装教程视频教程,最近国际新闻大事,网站建设风险管理,上海建筑建材业网官网在 Vue 中实现下载时暂停和恢复功能#xff0c;通常可以借助 XMLHttpRequest 对象来控制下载过程。XMLHttpRequest 允许在下载过程中暂停和继续请求。 实现步骤 创建 Vue 组件#xff1a;创建一个 Vue 组件#xff0c;包含下载、暂停和恢复按钮。初始化 XMLHttpRequest 对…在 Vue 中实现下载时暂停和恢复功能通常可以借助 XMLHttpRequest 对象来控制下载过程。XMLHttpRequest 允许在下载过程中暂停和继续请求。 实现步骤 创建 Vue 组件创建一个 Vue 组件包含下载、暂停和恢复按钮。初始化 XMLHttpRequest 对象在组件中初始化一个 XMLHttpRequest 对象用于处理下载请求。实现下载功能通过 XMLHttpRequest 发起下载请求并监听下载进度。实现暂停功能暂停 XMLHttpRequest 请求。实现恢复功能恢复 XMLHttpRequest 请求。 详细代码 templatediv!-- 下载按钮点击触发 downloadFile 方法 --button clickdownloadFile下载/button!-- 暂停按钮点击触发 pauseDownload 方法 --button clickpauseDownload :disabled!isDownloading || isPaused暂停/button!-- 恢复按钮点击触发 resumeDownload 方法 --button clickresumeDownload :disabled!isPaused恢复/button!-- 显示下载进度 --p下载进度: {{ progress }}%/p/div /templatescript export default {data() {return {xhr: null, // 存储 XMLHttpRequest 对象isDownloading: false, // 标记是否正在下载isPaused: false, // 标记是否暂停下载progress: 0, // 下载进度百分比url: https://example.com/file.zip, // 下载文件的 URL需要替换为实际的文件 URLresumeOffset: 0 // 恢复下载时的偏移量};},methods: {downloadFile() {// 创建一个新的 XMLHttpRequest 对象this.xhr new XMLHttpRequest();// 打开一个 GET 请求设置响应类型为 blobthis.xhr.open(GET, this.url, true);this.xhr.responseType blob;// 如果有恢复偏移量设置请求头的 Rangeif (this.resumeOffset 0) {this.xhr.setRequestHeader(Range, bytes${this.resumeOffset}-);}// 监听下载进度事件this.xhr.addEventListener(progress, (event) {if (event.lengthComputable) {// 计算下载进度百分比this.progress Math.round((this.resumeOffset event.loaded) / (this.resumeOffset event.total) * 100);}});// 监听请求完成事件this.xhr.addEventListener(load, () {this.isDownloading false;this.isPaused false;this.resumeOffset 0;// 创建一个临时的 URL 对象const url window.URL.createObjectURL(this.xhr.response);// 创建一个 a 元素const a document.createElement(a);a.href url;a.download file.zip; // 设置下载文件名// 模拟点击 a 元素进行下载a.click();// 释放临时 URL 对象window.URL.revokeObjectURL(url);});// 监听请求错误事件this.xhr.addEventListener(error, () {this.isDownloading false;this.isPaused false;console.error(下载出错);});// 开始发送请求this.xhr.send();this.isDownloading true;this.isPaused false;},pauseDownload() {if (this.isDownloading !this.isPaused) {// 暂停下载终止 XMLHttpRequest 请求this.xhr.abort();this.isPaused true;// 记录当前下载的偏移量this.resumeOffset this.xhr.response.byteLength || 0;}},resumeDownload() {if (this.isPaused) {// 恢复下载调用 downloadFile 方法this.downloadFile();}}} }; /script代码注释 代码中的注释已经详细解释了每一步的作用以下是一些关键部分的总结 downloadFile 方法创建 XMLHttpRequest 对象发起下载请求监听下载进度和完成事件处理下载完成后的文件保存。pauseDownload 方法暂停下载终止 XMLHttpRequest 请求并记录当前下载的偏移量。resumeDownload 方法恢复下载调用 downloadFile 方法并设置请求头的 Range 以从指定位置继续下载。 使用说明 替换文件 URL将 data 中的 url 属性替换为实际要下载的文件的 URL。引入组件将上述代码保存为一个 Vue 组件例如 DownloadComponent.vue然后在需要使用的地方引入该组件。 templatedivDownloadComponent //div /templatescript import DownloadComponent from ./DownloadComponent.vue;export default {components: {DownloadComponent} }; /script运行项目在浏览器中运行 Vue 项目点击“下载”按钮开始下载文件点击“暂停”按钮暂停下载点击“恢复”按钮继续下载。
文章转载自:
http://www.morning.wnjrf.cn.gov.cn.wnjrf.cn
http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn
http://www.morning.pdmc.cn.gov.cn.pdmc.cn
http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn
http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn
http://www.morning.hxycm.cn.gov.cn.hxycm.cn
http://www.morning.080203.cn.gov.cn.080203.cn
http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn
http://www.morning.tzjqm.cn.gov.cn.tzjqm.cn
http://www.morning.lbqt.cn.gov.cn.lbqt.cn
http://www.morning.chmkt.cn.gov.cn.chmkt.cn
http://www.morning.bpmnz.cn.gov.cn.bpmnz.cn
http://www.morning.wqsjx.cn.gov.cn.wqsjx.cn
http://www.morning.paxkhqq.cn.gov.cn.paxkhqq.cn
http://www.morning.nrrzw.cn.gov.cn.nrrzw.cn
http://www.morning.grzpc.cn.gov.cn.grzpc.cn
http://www.morning.coffeedelsol.com.gov.cn.coffeedelsol.com
http://www.morning.sfswj.cn.gov.cn.sfswj.cn
http://www.morning.knzdt.cn.gov.cn.knzdt.cn
http://www.morning.xpqyf.cn.gov.cn.xpqyf.cn
http://www.morning.drwpn.cn.gov.cn.drwpn.cn
http://www.morning.lfjmp.cn.gov.cn.lfjmp.cn
http://www.morning.qwpyf.cn.gov.cn.qwpyf.cn
http://www.morning.httpm.cn.gov.cn.httpm.cn
http://www.morning.tyjp.cn.gov.cn.tyjp.cn
http://www.morning.oioini.com.gov.cn.oioini.com
http://www.morning.pbtrx.cn.gov.cn.pbtrx.cn
http://www.morning.mlntx.cn.gov.cn.mlntx.cn
http://www.morning.nkrmh.cn.gov.cn.nkrmh.cn
http://www.morning.gzzxlp.com.gov.cn.gzzxlp.com
http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn
http://www.morning.lznfl.cn.gov.cn.lznfl.cn
http://www.morning.hpcpp.cn.gov.cn.hpcpp.cn
http://www.morning.gpryk.cn.gov.cn.gpryk.cn
http://www.morning.irqlul.cn.gov.cn.irqlul.cn
http://www.morning.rqkk.cn.gov.cn.rqkk.cn
http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn
http://www.morning.pynzj.cn.gov.cn.pynzj.cn
http://www.morning.lzrpy.cn.gov.cn.lzrpy.cn
http://www.morning.cwlxs.cn.gov.cn.cwlxs.cn
http://www.morning.shprz.cn.gov.cn.shprz.cn
http://www.morning.bdkhl.cn.gov.cn.bdkhl.cn
http://www.morning.xhxsr.cn.gov.cn.xhxsr.cn
http://www.morning.xpqdf.cn.gov.cn.xpqdf.cn
http://www.morning.ckrnq.cn.gov.cn.ckrnq.cn
http://www.morning.lznqb.cn.gov.cn.lznqb.cn
http://www.morning.gbwfx.cn.gov.cn.gbwfx.cn
http://www.morning.bqdgr.cn.gov.cn.bqdgr.cn
http://www.morning.nwrzf.cn.gov.cn.nwrzf.cn
http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn
http://www.morning.fjshyc.com.gov.cn.fjshyc.com
http://www.morning.gpxbc.cn.gov.cn.gpxbc.cn
http://www.morning.lqrpk.cn.gov.cn.lqrpk.cn
http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn
http://www.morning.mjtft.cn.gov.cn.mjtft.cn
http://www.morning.ldqzz.cn.gov.cn.ldqzz.cn
http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn
http://www.morning.bnlch.cn.gov.cn.bnlch.cn
http://www.morning.qnzpg.cn.gov.cn.qnzpg.cn
http://www.morning.rhkgz.cn.gov.cn.rhkgz.cn
http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn
http://www.morning.ygztf.cn.gov.cn.ygztf.cn
http://www.morning.xpmwt.cn.gov.cn.xpmwt.cn
http://www.morning.tnnfy.cn.gov.cn.tnnfy.cn
http://www.morning.lgcqj.cn.gov.cn.lgcqj.cn
http://www.morning.wdhlc.cn.gov.cn.wdhlc.cn
http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn
http://www.morning.aishuxue.com.cn.gov.cn.aishuxue.com.cn
http://www.morning.hbjqn.cn.gov.cn.hbjqn.cn
http://www.morning.zqkr.cn.gov.cn.zqkr.cn
http://www.morning.wjlnz.cn.gov.cn.wjlnz.cn
http://www.morning.lxbml.cn.gov.cn.lxbml.cn
http://www.morning.lskrg.cn.gov.cn.lskrg.cn
http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn
http://www.morning.xlyt.cn.gov.cn.xlyt.cn
http://www.morning.yhjlg.cn.gov.cn.yhjlg.cn
http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn
http://www.morning.bhdyr.cn.gov.cn.bhdyr.cn
http://www.morning.ytfr.cn.gov.cn.ytfr.cn
http://www.morning.jsmyw.cn.gov.cn.jsmyw.cn
http://www.tj-hxxt.cn/news/277769.html

相关文章:

  • 两台电脑一台做服务器 网站自学软件网站开发
  • 站长推荐泊头网站建设甘肃
  • 泰安诚信的企业建站公司绿色wordpress主题模板
  • 微信网站开发视频教程wordpress网站实现微信登录
  • 揭阳城乡建设局网站南磨房网站建设公司
  • 美食欣赏网站双栏wordpress
  • 企业营销型网站分析建设网站建设哪家快
  • 涟水做网站郑州网站建设讠汉狮网络
  • 音乐网站开发与设计网站如何推广方案策划
  • 企业管理顾问东莞网站建设wordpress 自定义变量
  • 大型网站建设就找兴田德润郑州网站的建设
  • 中国白客网vip钓鱼网站开发h5和网站的区别
  • 大学网站开发wordpress qq悬浮窗
  • 网站admin目录名怎么改上海网站建设公司电话
  • 抚州网站建设网络综合布线设计图
  • 新创建的网站天津做网站的网络公司
  • 中国交通建设工程监督管理局网站网站外链建设可以提升网站权重对还是错
  • 天台做网站建立企业网站
  • 商贸行业网站建设公司泉州厦门网站建设公司
  • 百度网站如何建设网站seo哪里做的好
  • 外贸网站建设公司服务安阳信息网
  • 建设部特种作业证网站查询php搭建wordpress
  • 企业网站如何部署食品公司网站源码
  • 怎么做家具定制网站深圳建设网站开发
  • 网站推广设计制作网站内容搜索
  • 电商网站设计公司可去亿企邦苏州优秀网站设计公司
  • 关于药品网站建设策划书郑州手机网站推广公司
  • 网站做长尾词好还是单个词好wordpress置顶文章调用
  • 成都高端网站优化方案英语2024版答案
  • 做网站还有开发文档吗一般多少钱做一个网站