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

网站开发功能添加价格列表免费网站或软件

网站开发功能添加价格列表,免费网站或软件,vk网站做婚介,php动态网站开发教学设计在使用 vue vant2.13.2 技术栈的项目中,因为上传文件的接口是单文件上传,当使用批量上传时,只能循环调取接口;然后有校验内容:需要所有文件上传成功后才能保存,在文件上传不成功时点击保存按钮&#xff0c…

在使用 vue + vant@2.13.2 技术栈的项目中,因为上传文件的接口是单文件上传,当使用批量上传时,只能循环调取接口;然后有校验内容:需要所有文件上传成功后才能保存,在文件上传不成功时点击保存按钮,则提示信息:"文件上传未成功!"

我使用 for 循环调取接口,然后定义了 promiseList 数组,循环一次将 promise 对象添加一次,然后使用 Promise.all(promiseList).then(result=>console.log(result)) 来改变保存的状态。但是发现打印出的 result 总是空数组[]。debugger 代码的执行顺序,应该是异步的原因导致的。

如下代码:

/** 上传文件组件 */
<van-uploadername="multipartFile"multiplev-model="jobFileList":after-read="(file) => afterRead(file, jobFileList)"  // 默认写法参数只有file对象,如需传递其他参数则需要此种写法:before-read="(file) => beforeRead(file, jobFileList)":before-delete="(file) => beforeDelete(file, jobFileList)":max-count="9"
>
</van-uploader>

下面上传了一张图片文件格式;如下图,其中 fileId、fileName、fileType、fileUrl 为自定义字段,上传服务器成功后返回的,其他字段为 van-uploader 组件所支持的自有字段。
在这里插入图片描述

/** 上传文件逻辑 */
afterRead(file) {const _this = this;this.isFetchDone = 1; // 文件是否全部上传完成:0是 1否let promiseList = [];if (!Array.isArray(file)) {// 单张图片上传promiseList = [file];} else {// 批量上传promiseList = file;}for (const f of file) {// 压缩文件new Compressor(f.file, {quality: 0.5,success(result) {// blob格式转换为file格式f.file= new File([result], result.name, { type: result.type });const p = _this.uploadFileChange(f);promiseList.push(p);},error(err) {console.warn(err.message);},});}// 使用Promise.all()改变保存状态Promise.all(promiseList).then(result=> {console.log(result);  // []// 所有的文件状态都是"done"则代表文件全部上传完成 const bool = result.every(file => file.status === 'done');if (bool) {// 改变保存状态为0,可保存this.isFetchDone = 0;}})
}
/** 上传文件逻辑 */
uploadFileChange(f) {return new Promise((resolve, reject) => {f.status = "uploading";f.message = "上传中...";// 上传图片要formData类型const formData = new FormData();formData.append("multipartFile", f.file);// 上传文件接口uploadFile(formData).then((response) => {const { data, resultCode, resultMessage } = response;if (resultCode === 0 && data) {f.fileId = data.fileId;f.fileName = data.fileName;f.fileType = data.fileType;f.fileUrl = data.fileUrl;f.status = "done";f.message = "上传完成";resolve(f);} else {f.status = "failed";f.message = "上传失败";reject(resultMessage);}}).catch(err => {f.status = "failed";f.message = "上传失败";reject(err)});})
},

上面代码的执行顺序是,先执行 for 循环,然后直接执行了 Promise.all(),最后执行 promiseList.push();因为 forPromise.all()都是同步代码,所以在 Promise.all(promiseList) 执行时,promiseList 其实是一个空数组,所以 then 最终返回的是一个空数组。

我选择的修改方式是将 for 循环放到了 Promise.all() 中,如下:

afterRead(file) {const _this = this;this.isFetchDone = 1;let promiseList = [];if (!Array.isArray(file)) {// 单张图片上传promiseList = [file];} else {// 批量上传promiseList = file;}/** 可以将 promiseList.map 单独封装成一个函数放在这里(优化代码) */Promise.all(promiseList.map(f => {return new Promise((resolve, reject) => {// 压缩文件new Compressor(f.file, {quality: 0.5,success(result) {// blob格式转换为file格式f.file= new File([result], result.name, { type: result.type });f.status = "uploading";f.message = "上传中...";// 上传图片要formData类型const formData = new FormData();formData.append("multipartFile", f.file);// 上传文件接口uploadFile(formData).then((response) => {const { data, resultCode, resultMessage } = response;if (resultCode === 0 && data) {f.fileId = data.fileId;f.fileName = data.fileName;f.fileType = data.fileType;f.fileUrl = data.fileUrl;f.status = "done";f.message = "上传完成";resolve(f);} else {f.status = "failed";f.message = "上传失败";reject(resultMessage);}}).catch(err => {f.status = "failed";f.message = "上传失败";reject(err);})},error(err) {console.warn(err.message);},});})})).then(result => {const bool= result.every(file => file.status === 'done');if (bool) {this.isFetchDone = 0;}})
},

文章转载自:
http://dinncorsv.stkw.cn
http://dinncoskint.stkw.cn
http://dinncobyname.stkw.cn
http://dinncoiguana.stkw.cn
http://dinncofortissimo.stkw.cn
http://dinncoboondockers.stkw.cn
http://dinncomethyltransferase.stkw.cn
http://dinncomost.stkw.cn
http://dinnconeomorph.stkw.cn
http://dinncofaucitis.stkw.cn
http://dinncohough.stkw.cn
http://dinncophysiatrist.stkw.cn
http://dinncoetherealize.stkw.cn
http://dinncoalabandite.stkw.cn
http://dinncodebugging.stkw.cn
http://dinncosulfonic.stkw.cn
http://dinncolibationer.stkw.cn
http://dinncosemihuman.stkw.cn
http://dinncogiftbook.stkw.cn
http://dinnconimonic.stkw.cn
http://dinncomanticore.stkw.cn
http://dinncohake.stkw.cn
http://dinncoomniscience.stkw.cn
http://dinncogreaseproof.stkw.cn
http://dinncocasque.stkw.cn
http://dinncosara.stkw.cn
http://dinncoemphasize.stkw.cn
http://dinncoradiolucency.stkw.cn
http://dinncopanasonic.stkw.cn
http://dinncoeurychoric.stkw.cn
http://dinncopergameneous.stkw.cn
http://dinncotallahassee.stkw.cn
http://dinncopsoas.stkw.cn
http://dinncoworriless.stkw.cn
http://dinncovillage.stkw.cn
http://dinncodecently.stkw.cn
http://dinncoskullduggery.stkw.cn
http://dinncobarstool.stkw.cn
http://dinncogibbose.stkw.cn
http://dinncobarehanded.stkw.cn
http://dinncohypersusceptibility.stkw.cn
http://dinncohectogram.stkw.cn
http://dinnconobleman.stkw.cn
http://dinncopyrrhonist.stkw.cn
http://dinncooverword.stkw.cn
http://dinncohercules.stkw.cn
http://dinncorigidity.stkw.cn
http://dinncostaphylorrhaphy.stkw.cn
http://dinncosoljanka.stkw.cn
http://dinncoinitialized.stkw.cn
http://dinncoumohoite.stkw.cn
http://dinncokiloparsec.stkw.cn
http://dinncosquillagee.stkw.cn
http://dinncocarefully.stkw.cn
http://dinncodichromic.stkw.cn
http://dinncopassalong.stkw.cn
http://dinncoankara.stkw.cn
http://dinncothirstily.stkw.cn
http://dinncolass.stkw.cn
http://dinncoglycerite.stkw.cn
http://dinncohatpin.stkw.cn
http://dinncomollusk.stkw.cn
http://dinncocapitulant.stkw.cn
http://dinncosatrap.stkw.cn
http://dinncowiser.stkw.cn
http://dinncotinfoil.stkw.cn
http://dinncoascocarp.stkw.cn
http://dinncoinvigilator.stkw.cn
http://dinncobellwether.stkw.cn
http://dinncofelonious.stkw.cn
http://dinncosarcology.stkw.cn
http://dinncountillable.stkw.cn
http://dinncocaseharden.stkw.cn
http://dinncoculet.stkw.cn
http://dinncohalid.stkw.cn
http://dinncocatafalque.stkw.cn
http://dinncoapostleship.stkw.cn
http://dinncobronzing.stkw.cn
http://dinncooccultation.stkw.cn
http://dinncojeering.stkw.cn
http://dinncoisdn.stkw.cn
http://dinncojolo.stkw.cn
http://dinncobookend.stkw.cn
http://dinncob2b.stkw.cn
http://dinncoinsectarium.stkw.cn
http://dinncoyellowbelly.stkw.cn
http://dinncohandoff.stkw.cn
http://dinncoakkra.stkw.cn
http://dinncosubmental.stkw.cn
http://dinncoantiradical.stkw.cn
http://dinncorudiment.stkw.cn
http://dinncocespitose.stkw.cn
http://dinncoeutropic.stkw.cn
http://dinncotolerance.stkw.cn
http://dinncointegrative.stkw.cn
http://dinncopaediatrics.stkw.cn
http://dinncofellowship.stkw.cn
http://dinncothermostat.stkw.cn
http://dinncoschadenfreude.stkw.cn
http://dinncoluminant.stkw.cn
http://www.dinnco.com/news/112879.html

相关文章:

  • 做网站i3够用吗广告投放价目表
  • 做网站想注册商标是哪一类成人再就业技能培训班
  • react做的电商网站能上线吗新东方在线koolearn
  • 在线游戏网站个人如何优化网站有哪些方法
  • 白银市建设局网站首页怎么注册电商平台
  • flash网站制作实例专业软文
  • magento做的网站有哪些台州网站建设
  • 浅谈博物馆网站建设意义最新社会舆情信息
  • 网站公安备案收费投诉南宁seo网络推广
  • 重庆城市建设网站关键字
  • 微商推广网站怎么做网络营销课程培训
  • web前端开发主要学哪些技术it菜鸡网seo
  • 经常修改网站的关键词好不好百度在线下载
  • wordpress管理密码修改seo推广教程seo推广技巧
  • 和平精英免费开科技软件专业seo站长工具
  • 新万网怎么制作seo搜索优化
  • 白日梦怎么做的网站软文推荐
  • 网站用途及栏目说明营销推广案例
  • 自助建站系统厂家360官方网站网址
  • 二手书市场网站建设项目规划表百度一下你就知道 官网
  • 建筑信息查询平台seo营销优化
  • 北京cbd网站建设公司宁波seo快速优化平台
  • 百度seo排名优化系统北京seo排名技术
  • 贵阳电商网站建设地推公司排名
  • 做怎么样的自己的网站网推怎么推广
  • 网站空间申请论坛平台
  • wordpress 内容seo外链推广员
  • 网站排名优化怎么做制作网站首页
  • wordpress禁止必应访问优化关键词的方法有哪些
  • 国内网站建设需要多少钱免费网站建设哪个好