温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在vue中使用el-upload上传图片

发布时间:2021-04-12 17:21:27 来源:亿速云 阅读:524 作者:Leah 栏目:web开发

怎么在vue中使用el-upload上传图片?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

<el-input v-model="listVideoQuery.orgLogo" @change="orgLogoChange"></el-input>   <el-col :span="10" class="mt10">   <el-upload class="upload-demo" :file-list="fileList2" :action="domain" :before-upload="beforeAvatarUpload" :data="form"   :on-remove="handleRemoveQrgLogo" :on-success="handleAvatarSuccess" list-type="picture" :limit="1" multiple>   <el-button size="small" type="primary" @click="upPicName='orgLogo'">点击上传</el-button>   <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>   </el-upload>   </el-col> export default {  name: 'edit',  data() {  return {  upPicName:'', //上传图片名字  fileList1:[],  form: {}, //上传到七牛的token   bucketQuery:{   bucket: 'website-image' //这是我用来获取token传给后台的字段  },  domain: 'http://upload.qiniu.com', // 七牛云的上传地址  qiniuaddr: 'pd6rnk9ck.bkt.clouddn.com' // 这是七牛云空间的外链默认域名  }  },  methods: {  // 上传图片规格  beforeAvatarUpload (file) {  const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'  const isLt2M = file.size / 1024 / 1024 < 5  if (!isJPG) {   return this.$message.error('上传文件只能是 JPG或PNG 格式!')  }  if (!isLt2M) {   return this.$message.error('上传图片大小不能超过 5MB!')  }  return upQiniu(this.bucketQuery).then(res => {   this.form = {   token:res.data   }  })  },  //图片改变及上传  bannerPicChange(value) {  this.fileList1 = []  this.fileList1.push({   name: value,    url: value  })   },  handleBannerPicRemove(file, fileList) {  this.fileList1 = []  this.listVideoQuery.orgLogo= ''  },  handleAvatarSuccess(response) {  if(this.upPicName =='orgLogo'){   this.fileList1 = []   this.fileList1.push({   name: 'http://' + this.qiniuaddr + '/' + response.key,    url: 'http://' + this.qiniuaddr + '/' + response.key   })    this.listVideoQuery.orgLogo= 'http://' + this.qiniuaddr + '/' + response.key  }  this.$message({   type: 'success',   message: '上传成功!',   duration: 2000  })   },  }  }

看完上述内容,你们掌握怎么在vue中使用el-upload上传图片的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI