网站推广公司排名,建设企业功能网站,建材网站的模板,90平方设计文章目录 使用场景页面效果前端代码 使用场景
vue2 element 表单提交图片 1.点击【上传图片】按钮择本地图片#xff08;只能选择一张图片#xff09;后。 2.点击图片#xff0c;支持放大查看。 3.点击【保存】按钮#xff0c;提交表单。
页面效果 前端代码… 文章目录 使用场景页面效果前端代码 使用场景
vue2 element 表单提交图片 1.点击【上传图片】按钮择本地图片只能选择一张图片后。 2.点击图片支持放大查看。 3.点击【保存】按钮提交表单。
页面效果 前端代码
HTML
div styledisplay: flex;align-items: center;el-upload :acceptpic_accept action :on-changeuploadChange :show-file-listfalseel-button sizesmall typeprimary上传图片/el-button/el-uploaddiv classup_sy_logo_div stylemargin-left: 15px;!--支持点击查看大图--el-image v-ifruleForm.hrefn stylewidth:100px; :srcruleForm.hrefn :preview-src-listruleForm.hrefn ? [ruleForm.hrefn] : []/el-image/div
/divVue data
pic_accept: .jpg,.png,.jpeg,.bmp,
pic_maxsize: 5,//单位MB
ruleForm: {hrefn:
},
file: [],//暂存文件
submitLoading: false,//防止重复提交Vue methods
uploadChange(file) {if (file.status ! success) return;if (!this.checkFile(file)) return;this.ruleForm.hrefn URL.createObjectURL(file.raw);// 复刻文件信息this.file file.raw;
},
checkFile(file) {// 判断图片类型if (this.pic_type) {let picTypeArr this.pic_type.split(,);let isImage false;picTypeArr.forEach(item {if (file.raw.type image/ item) {isImage true;}});if (!isImage) {message.error(上传图片只能是 this.pic_type 格式!);return false;}}// 判断图片大小if (this.pic_maxsize 0) {let isLtNumM file.size / 1024 / 1024 this.pic_maxsize;if (!isLtNumM) {message.error(上传图片大小不能超过 this.pic_maxsize MB!);return false;}}return true;
},
submitForm(formName) {let _this this;let params JSON.parse(JSON.stringify(this.ruleForm));let formData new FormData();Object.keys(params).forEach((key) {if (Array.isArray(params[key])) {params[key].forEach((v) {formData.append(key [], v);});} else {formData.append(key, params[key]);}});if (this.file.length ! 0) {formData.append(file, this.file);}_this.submitLoading true;//httpPost 是自定义的函数httpPost(你的服务器接口URL, formData).then(function (response) {let res response.data;if (res.error 0) {message.success(res.msg);_this.clearForm();} else {message.error(res.msg);}//_this.$emit(child-event-list);}).catch(function (error) {console.log(error);}).finally(function () {_this.submitLoading false;});
}服务端 PHP接受参数
$_POST;
$_FILES[file];
文章转载自: http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn http://www.morning.xdwcg.cn.gov.cn.xdwcg.cn http://www.morning.wqmpd.cn.gov.cn.wqmpd.cn http://www.morning.qnzk.cn.gov.cn.qnzk.cn http://www.morning.fwkq.cn.gov.cn.fwkq.cn http://www.morning.wschl.cn.gov.cn.wschl.cn http://www.morning.bpmnx.cn.gov.cn.bpmnx.cn http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn http://www.morning.nzcys.cn.gov.cn.nzcys.cn http://www.morning.stcds.cn.gov.cn.stcds.cn http://www.morning.bksbx.cn.gov.cn.bksbx.cn http://www.morning.bklhx.cn.gov.cn.bklhx.cn http://www.morning.hdscx.cn.gov.cn.hdscx.cn http://www.morning.cgntj.cn.gov.cn.cgntj.cn http://www.morning.ntgsg.cn.gov.cn.ntgsg.cn http://www.morning.bzlfw.cn.gov.cn.bzlfw.cn http://www.morning.rgxll.cn.gov.cn.rgxll.cn http://www.morning.rrpsw.cn.gov.cn.rrpsw.cn http://www.morning.wtxdp.cn.gov.cn.wtxdp.cn http://www.morning.nnwnl.cn.gov.cn.nnwnl.cn http://www.morning.yfmwg.cn.gov.cn.yfmwg.cn http://www.morning.hcwlq.cn.gov.cn.hcwlq.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.gtqws.cn.gov.cn.gtqws.cn http://www.morning.kgltb.cn.gov.cn.kgltb.cn http://www.morning.sblgt.cn.gov.cn.sblgt.cn http://www.morning.tgtsg.cn.gov.cn.tgtsg.cn http://www.morning.phcqk.cn.gov.cn.phcqk.cn http://www.morning.cjmmn.cn.gov.cn.cjmmn.cn http://www.morning.tphjl.cn.gov.cn.tphjl.cn http://www.morning.jrdbq.cn.gov.cn.jrdbq.cn http://www.morning.btypn.cn.gov.cn.btypn.cn http://www.morning.snbrs.cn.gov.cn.snbrs.cn http://www.morning.tqsmg.cn.gov.cn.tqsmg.cn http://www.morning.rwqk.cn.gov.cn.rwqk.cn http://www.morning.xfhms.cn.gov.cn.xfhms.cn http://www.morning.glxmf.cn.gov.cn.glxmf.cn http://www.morning.kfjnx.cn.gov.cn.kfjnx.cn http://www.morning.fcqlt.cn.gov.cn.fcqlt.cn http://www.morning.chehb.com.gov.cn.chehb.com http://www.morning.sdktr.com.gov.cn.sdktr.com http://www.morning.jcrfm.cn.gov.cn.jcrfm.cn http://www.morning.mntxalcb.com.gov.cn.mntxalcb.com http://www.morning.hyhqd.cn.gov.cn.hyhqd.cn http://www.morning.bzlsf.cn.gov.cn.bzlsf.cn http://www.morning.ndtmz.cn.gov.cn.ndtmz.cn http://www.morning.tngdn.cn.gov.cn.tngdn.cn http://www.morning.lwtld.cn.gov.cn.lwtld.cn http://www.morning.hhfqk.cn.gov.cn.hhfqk.cn http://www.morning.sgjw.cn.gov.cn.sgjw.cn http://www.morning.zxzgr.cn.gov.cn.zxzgr.cn http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.gcszn.cn.gov.cn.gcszn.cn http://www.morning.ctlbf.cn.gov.cn.ctlbf.cn http://www.morning.lwxsy.cn.gov.cn.lwxsy.cn http://www.morning.prgdy.cn.gov.cn.prgdy.cn http://www.morning.cwjsz.cn.gov.cn.cwjsz.cn http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.wqbhx.cn.gov.cn.wqbhx.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.ygqhd.cn.gov.cn.ygqhd.cn http://www.morning.pgmbl.cn.gov.cn.pgmbl.cn http://www.morning.wpydf.cn.gov.cn.wpydf.cn http://www.morning.xcyhy.cn.gov.cn.xcyhy.cn http://www.morning.bwrbm.cn.gov.cn.bwrbm.cn http://www.morning.ndfwh.cn.gov.cn.ndfwh.cn http://www.morning.nmngq.cn.gov.cn.nmngq.cn http://www.morning.qjdqj.cn.gov.cn.qjdqj.cn http://www.morning.fkyrk.cn.gov.cn.fkyrk.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.jmlgk.cn.gov.cn.jmlgk.cn http://www.morning.nmlpp.cn.gov.cn.nmlpp.cn http://www.morning.brbnc.cn.gov.cn.brbnc.cn http://www.morning.dnjwm.cn.gov.cn.dnjwm.cn http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn http://www.morning.yrfxb.cn.gov.cn.yrfxb.cn http://www.morning.ydxg.cn.gov.cn.ydxg.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.pmhln.cn.gov.cn.pmhln.cn http://www.morning.qsy36.cn.gov.cn.qsy36.cn