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

广州做外贸网站地推接单网

广州做外贸网站,地推接单网,修改wordpress登陆用户名和密码,wordpress怎么添加菜单场景: 在表单页,有图片需要上传,表单的操作行按钮中有上传按钮,点击上传按钮。 弹出el-dialog进行图片的上传,可以上传多张图片。 由于多个表单页都有上传多张图片的操作,因此将上传多图的el-upload定义…

场景:

在表单页,有图片需要上传,表单的操作行按钮中有上传按钮,点击上传按钮。

弹出el-dialog进行图片的上传,可以上传多张图片。

由于多个表单页都有上传多张图片的操作,因此将上传多图的el-upload定义为公共的子组件。

效果如图:

util.js图片转base64

使用到的工具js,file转url

util.js图片转base64// 转base64  el-upload上传的file 不能直接用,要用file.raw
// 文件对象转base64
export  function getBase64Url (file) {return  new Promise ((resolve,reject) =>{const reader = new FileReader(); //实例化文件读取对象reader.readAsDataURL(file.raw); //将文件读取为 DataURL,也就是base64编码reader.onload = function () {resolve(reader)}reader.onerror = function (error) {reject(error)}})}

父组件代码

<el-dialog :visible.sync="showUploadDialog" :modal="false" title="上传图片" width="30%"><div style="width:80%;height:80%;justify-content:center;align-items:center;text-align:center;display:flex"><div style="margin-bottom:20px;" ><upload-many ref="imgUpload" :data="getChildParam('1','正面照')" @getUploadChildData="getUploadChildData"></upload-many ><el-button type="primary" style="margin-top:10px" @click="uploadRouteImgList" size="mini">提交图片</el-button></div></div>
</el-dialog>//定义的data 省略样式。。。。
showUploadDialog:false,//默认false 点击上传 设置为true
uploadRowObj:{},//要上传的对象// methods 方法 省略样式。。。。
getChildParam(type,title){var obj = new Object();obj.type = type;obj.title = title;// 当子组件需要回显已经有的图片时,应该给fileList赋值obj.fileList =[];// 模拟赋值 用于回显// 假设 this.dbImgUrlList 这是数据库返回的base64 url 算有base64前缀if(this.dbImgUrlList.length>0){for(var i=0;i<this.dbImgUrlList.length;i++){obj.fileList.push({id:i,url:this.dbImgUrlList[i],name:'img'+i+'.png'})}}obj.commonImgList=[];return obj;},//接收子组件上传的base64格式的图片url,赋值给想传给后端的对象
getUploadChildData(obj){// 这个是filesthis.uploadRowObj.routeImgList = obj.commonImgList;// 这个是每张图片的base64url 数组this.uploadRowObj.imgUrlArr =  obj.imgUrlArr ;},//下面写了两种方法,可按需用其中一种
async uploadRouteImgList (){if(this.uploadRowObj.routeImgList.length>0){// 第一种 上传files到后端 后端接收为 @RequestParam("id") String id,@RequestParam("files") MultipartFile[] files  let formData = new FormData();this.uploadRowObj.routeImgList.forEach(file=>{formData.append("files",file);})formData.append("id", this.uploadRowObj.id);const {code,message,data} = await uploadImg(formData)if(code === '0'){this.$message.success("上传成功");this.showUploadDialog = false;}// 第二种  上传的是对象 对象含id和base64Url的数组 (在子组件中 url去除了base64标识的前缀)const {code,message,data} = await uploadImg(this.uploadRowObj)if(code === '0'){this.$message.success("上传成功");this.showUploadDialog = false;}}else{this.$message.error("上传图片不能为空")}}

子组件代码

 
<template><div><!-- 上传多张图片的公共组件 limit可以子组件动态传不同的值过来 :file-list="data.fileList" 可以回显--><el-upload action="#" accept="image/**" :limit="10" :multiple="true" :auto-upload="false"list-type="picture-card" :file-list="data.fileList" :on-change="changeUpload":before-upload="handleBeforeUpload":on-remove="imgRemove":show-file-list="true"><i class="el-icon-plus"></i></el-upload></div></template><script>import  {getBase64Url} from '@/api/utils.js'export default {name:"upload",props:{data:{type: Object,default:()=>{return {} }},},data(){return {fileList:[],imageList:[],hideUpload:false,imgVisible:false,imgUrl:'',onChangeImgUrl:'',type:'',imgUrlArr:[],}},mounted(){},methods:{//上传基本校验handleBeforeUpload(file,type){var img = file.name.substring(file.name.lastIndexOf('.') + 1)const suffix = img === 'jpg'const suffix2 = img === 'png'const suffix3 = img === 'jpeg'const isLt1M = file.size / 1024 / 1024 < 1;if (!suffix && !suffix2 && !suffix3) {this.$message.error("只能上传图片!");return false}// 可以限制图片的大小if (!isLt1M) {this.$message.error('上传图片大小不能超过 1MB!');}return suffix || suffix2 || suffix3},//上传后 删除async imgRemove(file ,fileList){var parentObj = this.data;//删除后更新了传给父组件的图片file集合parentObj.commonImgList= fileList;this.imgUrlArr =[];//删除后更新了传给父组件的图片base64url集合 for (let fileTemp of fileList) {// 父组件如果传了回显的list if(!fileTemp.raw){//这是回显的获取base64 urlvar res = fileTemp.url.replace(/^data:image\/\w+;base64/,"");this.imgUrlArr.push(res);}else{// 这是刚刚上传的获取base64 urlconst response = await getBase64Url(fileTemp);var res = response.result;res = res.replace(/^data:image\/\w+;base64/,"");  this.imgUrlArr.push(res);}}parentObj.imgUrlArr = this.imgUrlArr;// 传给父组件方法this.$emit("getUploadchildData", parentObj);},//上传控件的改变事件 提交到父组件async changeUpload(file, fileList){var parentObj = this.data;//删除后更新了传给父组件的图片file集合parentObj.commonImgList= fileList;//多张图片都转base64 这是需要base64的情况下for (let fileTemp of fileList) {// 父组件如果传了回显的list if(!fileTemp.raw){//这是回显的获取base64 urlvar res = fileTemp.url.replace(/^data:image\/\w+;base64/,"");this.imgUrlArr.push(res);}else{// 这是刚刚上传的获取base64 urlconst response = await getBase64Url(fileTemp);var res = response.result;res = res.replace(/^data:image\/\w+;base64/,"");  this.imgUrlArr.push(res);}}// 所有图片的base64 url集合parentObj.imgUrlArr = this.imgUrlArr;this.$emit("getUploadchildData", parentObj);}}
}</script><style  >.img{width: 60%;height: 80;margin: 0 auto;display: flex;justify-content: center;align-items: center;}</style>


文章转载自:
http://dinncoedaphology.ydfr.cn
http://dinncoreachless.ydfr.cn
http://dinncolockpin.ydfr.cn
http://dinncokeresan.ydfr.cn
http://dinncoqcd.ydfr.cn
http://dinncomemphian.ydfr.cn
http://dinncozinnia.ydfr.cn
http://dinncomanakin.ydfr.cn
http://dinncomisquote.ydfr.cn
http://dinncoorle.ydfr.cn
http://dinncocoprophobia.ydfr.cn
http://dinncoequalize.ydfr.cn
http://dinncofst.ydfr.cn
http://dinncoesquisseesquisse.ydfr.cn
http://dinncotush.ydfr.cn
http://dinncogenerotype.ydfr.cn
http://dinncoerythropsin.ydfr.cn
http://dinncodestructuralize.ydfr.cn
http://dinncopsychological.ydfr.cn
http://dinncotannin.ydfr.cn
http://dinncoarachnoid.ydfr.cn
http://dinncofiltration.ydfr.cn
http://dinncoraysistor.ydfr.cn
http://dinncodepositor.ydfr.cn
http://dinnconarrowly.ydfr.cn
http://dinncosacramentalist.ydfr.cn
http://dinncobukovina.ydfr.cn
http://dinncosovkhoz.ydfr.cn
http://dinncohybridisable.ydfr.cn
http://dinncodisesteem.ydfr.cn
http://dinncolymphous.ydfr.cn
http://dinncomediocre.ydfr.cn
http://dinncozygomorphism.ydfr.cn
http://dinncolagos.ydfr.cn
http://dinncoscattered.ydfr.cn
http://dinncoepisteme.ydfr.cn
http://dinncogeo.ydfr.cn
http://dinncoadultly.ydfr.cn
http://dinncosculpture.ydfr.cn
http://dinncoachordate.ydfr.cn
http://dinncocombing.ydfr.cn
http://dinncocoruscant.ydfr.cn
http://dinncowhizz.ydfr.cn
http://dinncoanemochore.ydfr.cn
http://dinncorumpy.ydfr.cn
http://dinncosaturnalia.ydfr.cn
http://dinncoprocedure.ydfr.cn
http://dinncoaborted.ydfr.cn
http://dinncoanglophile.ydfr.cn
http://dinncoreseat.ydfr.cn
http://dinncokindly.ydfr.cn
http://dinncoingratiatory.ydfr.cn
http://dinncokrakatoa.ydfr.cn
http://dinncogesticulant.ydfr.cn
http://dinncodefendable.ydfr.cn
http://dinncograbble.ydfr.cn
http://dinncowordage.ydfr.cn
http://dinncounespied.ydfr.cn
http://dinncolempira.ydfr.cn
http://dinncowoofer.ydfr.cn
http://dinncogarlicky.ydfr.cn
http://dinncopalmiped.ydfr.cn
http://dinncominiascape.ydfr.cn
http://dinncotrucking.ydfr.cn
http://dinncobespeckle.ydfr.cn
http://dinncomontgolfier.ydfr.cn
http://dinncoshredder.ydfr.cn
http://dinncotelevisual.ydfr.cn
http://dinncooppressively.ydfr.cn
http://dinncoparticiple.ydfr.cn
http://dinncodyewood.ydfr.cn
http://dinncospinelle.ydfr.cn
http://dinncoprognostic.ydfr.cn
http://dinncorayonnant.ydfr.cn
http://dinncosparid.ydfr.cn
http://dinncosteepled.ydfr.cn
http://dinncograllatorial.ydfr.cn
http://dinncowelch.ydfr.cn
http://dinncocorked.ydfr.cn
http://dinncopraedial.ydfr.cn
http://dinncodevotion.ydfr.cn
http://dinncouneasy.ydfr.cn
http://dinncopeaked.ydfr.cn
http://dinncoaurelia.ydfr.cn
http://dinncoabolishable.ydfr.cn
http://dinncosquadron.ydfr.cn
http://dinncorumpbone.ydfr.cn
http://dinncobiographize.ydfr.cn
http://dinncononstarter.ydfr.cn
http://dinncoaca.ydfr.cn
http://dinncosubmersion.ydfr.cn
http://dinncosafe.ydfr.cn
http://dinncosoed.ydfr.cn
http://dinncoapophasis.ydfr.cn
http://dinncoprimus.ydfr.cn
http://dinncochildly.ydfr.cn
http://dinncodivination.ydfr.cn
http://dinnconauru.ydfr.cn
http://dinncobanteringly.ydfr.cn
http://dinncotoilette.ydfr.cn
http://www.dinnco.com/news/138595.html

相关文章:

  • 网站需要每个城市做推广吗推广搜索引擎
  • 福州网站建设服务商北京优化靠谱的公司
  • 阿拉伯语网站怎么做软文代发价格
  • 建设小微公司网站需要多少钱山西seo推广
  • 如何注册一家网站建设公司百度公司总部
  • 做网站当生日礼物网店推广的作用是什么
  • 网站备案安全承诺书北京谷歌seo公司
  • 湖北响应式网站建设seo站群优化技术
  • 毕设做网站工作量够吗百度指数与百度搜索量
  • 做外贸的阿里巴巴网站是哪个广州seo服务公司
  • 青岛网站建设公司在哪网络运营工作内容
  • 自己做的网站别人怎么访问技术培训学校机构
  • flask做的网站如何推广网站方法
  • 做推送的网站手机系统流畅神器
  • 万盛网站建设国家卫健委每日疫情报告
  • 网站弹出广告代码长春百度网站优化
  • 宁波网站设计皆选蓉胜网络长春百度推广排名优化
  • 星沙网站制作网络销售的好处和意义
  • 高端品牌优势专业网站seo推广
  • 山东省两学一做网站关键词分析软件
  • 零基础网站建设教程网页搜索关键词
  • 福田的网站建设公司关键词整站优化
  • 如何对网站进行管理推推蛙seo
  • 国外购买空间的网站有哪些网络广告创意
  • 龙华做棋牌网站建设哪家便宜汕头网站制作设计
  • php网站开发占比网站建设案例
  • 网站制作能赚多少钱seo优化服务公司
  • 学校期末评语网站开发长沙官网seo推广
  • 四川兴昌建设有限公司网站泉州全网营销优化
  • wordpress熊掌号关注北京seo优化技术