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

青岛网站建设首选/搜索网站

青岛网站建设首选,搜索网站,网站空间安装,网站修改了关键词被降权业务上有需求是前端上传 jpg/png/gif 格式, 并且 尺寸为 150px * 150px,300px*300px,428*428px 的图片 同时在上传的同时需要携带用户的个人信息以及其他额外信息 因此在 element-upload 基础之上 实现这个需求需要在上传前检查图片的大小,格式以及尺寸如何上传也成…

业务上有需求是前端上传 jpg/png/gif 格式, 并且 尺寸为 150px * 150px,300px*300px,428*428px 的图片

  • 同时在上传的同时需要携带用户的个人信息以及其他额外信息

因此在 element-upload 基础之上

  • 实现这个需求需要在上传前检查图片的大小,格式以及尺寸
  • 如何上传也成为一个问题
    • 使用组件的 action 上传方式, body属性传递参数
  • 限制格式,加了一句:accept=“image/jpg,image/jpeg,image/png”

1-1 展示封装的组件

1-1-1 父组件

              <uploadPic form-label="上传大图片" :before-load="beforeLargeUpload" :dialog-pic-visible="dialogPicVisible" :picture-large-dim="ruleForm.pictureLarge" :upload-data="uploadLargeData" @changePicUrl="changePicUrl" /><uploadPic form-label="上传小图片" :before-load="beforeSmallUpload" :dialog-pic-visible="dialogPicVisible" :picture-large-dim="ruleForm.pictureSmall" :upload-data="uploadLargeData" @changePicUrl="changePicUrlSmall" /><script>
data(){return{dialogPicVisible: false,}
},
methods: {// 上传图片接收参数// 大图片changePicUrl(resUrl) {this.ruleForm.pictureLarge = resUrl},// 中间图片changePicUrlMedium(resUrl) {this.ruleForm.pictureMedium = resUrl},// 小图片changePicUrlSmall(resUrl) {this.ruleForm.pictureSmall = resUrl},// 上传大图片beforeLargeUpload(file) {// const isJPG = file.type === 'image/jpeg'const isLt2M = file.size / 1024 / 1024 < 2let is80x56 = trueconst reader = new FileReader()reader.readAsDataURL(file)reader.onload = (theFile) => {const image = new Image()image.src = theFile.target.resultimage.onload = () => {const { width, height } = imageif ((width !== 482) || (height !== 482)) {this.$message.error(`图片尺寸${width}*${height},请上传482*482 px 的图片!`)is80x56 = falsereturn}}}if (!isLt2M) {this.$message.error('上传头像图片大小不能超过 2MB!')}return new Promise((resolve, reject) => {(isLt2M && is80x56).catch(err => {return err})})},// 上传中图片// 上传小图片beforeMediumUpload(file) {const isLt2M = file.size / 1024 / 1024 < 2let is300 = trueconst reader = new FileReader()reader.readAsDataURL(file)reader.onload = (theFile) => {const image = new Image()image.src = theFile.target.resultimage.onload = () => {const { width, height } = imageif (width !== 150 && height !== 150) {this.$message.error(`图片尺寸${width}*${height},请上传 300*300 px 以下的图片!`)is300 = false}}}if (!isLt2M) {this.$message.error('上传头像图片大小不能超过 2MB!')}return new Promise((resolve, reject) => {(isLt2M && is300).catch(err => {return err})})},}
</script>

1-1-2 子组件 uploadPic

<template><div><el-form-item :label="formLabel"><div style="display:flex; justify-content:space-between;"><el-input v-model="pictureLargeDim" placeholder="请点击上传按钮" :disabled="true" /><el-button type="primary" @click="dialogPicVisible = true">上传</el-button></div><el-dialog :title="formLabel" :visible.sync="dialogPicVisible"><el-uploadclass="upload-demo":limit="1"accept="image/jpeg,image/gif,image/png"dragaction="/config/upload":data="uploadData":before-upload="beforeLoad":on-success="handleAvatarSuccess":on-exceed="handleExceed"><i class="el-icon-upload" /><div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div><div slot="tip" class="el-upload__tip">只能上传jpg/png/gif文件,且不超过2MB</div></el-upload></el-dialog></el-form-item></div>
</template><script>
export default {props: {pictureLargeDim: {type: String,required: true},uploadData: {type: Object,required: true},formLabel: {type: String,required: true},// 判断是大小中图片上传beforeLoad: {type: Function,required: true}},data() {return {dialogPicVisible: false}},methods: {handleAvatarSuccess(res) {//   this.ruleForm.pictureLarge = res.urlthis.$emit('changePicUrl', res.url)this.dialogPicVisible = falsethis.$message.success('上传成功')},handleExceed() {this.$message.warning('仅上传一张图片,删除之前的图片再进行之后的操作')}}
}
</script>

1-2

参考文章:https://blog.csdn.net/qq_41800366/article/details/113309320

  • https://blog.csdn.net/qq_58340302/article/details/125939912
http://www.jmfq.cn/news/5315221.html

相关文章:

  • 对电子商务网站建设与管理的心得/百度爱采购怎么推广
  • 网站建设需要配置环境么/免费html网站制作成品
  • 北京移动端网站建设/关键词排名推广方法
  • 山西省城乡住房和建设厅网站首页/1元购买域名
  • 二级学院网站建设自评报告/西安seo培训学校
  • 江西省城乡建设厅网站/外贸展示型网站建设公司
  • 邯郸做wap网站建设/建立企业网站步骤
  • 芜湖市住房和城乡建设厅网站首页/搜索引擎谷歌
  • 安徽建设厅网站考勤/关于校园推广的软文
  • 怎么从建设部网站下载规范/十五种常见的销售策略
  • 校园网站建设说明书/网络推广怎么做
  • 外贸网网站建设/网上营销的平台有哪些
  • 最新的网站建设架构/免费网站电视剧全免费
  • 加强企业网站建设的通知/搜索引擎优化公司
  • 望京SOHO网站建设/网站竞价推广托管公司
  • 网站建设35类/网络营销推广活动有哪些
  • 南京商城网站建设/seo怎么优化
  • 网站建设排版/电商网站seo
  • 苏州知名网站建设设计公司/关键词快速排名平台
  • 宁波市建设银行网站/佛山网站建设排名
  • 网站建设 中企动力南昌0792/开封网站seo
  • 外部链接链轮的建设对于网站提/兰州百度推广的公司
  • 58同城武汉网站建设/宣传推广方式
  • 电子商务企业网站建设规划/企业营销网站
  • 贵阳网站建设gzzctyi/seo包括哪些方面
  • js网站建设/百度竞价开户联系方式
  • 校园二手交易网站建设方案/杭州网站设计制作
  • 电子商务网站建设常用工具/新乡网站优化公司价格
  • 全国设计网站建设/女教师网课入06654侵录屏
  • 网站建设市场趋势/seo在线优化工具 si