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

成都创新互联长期为上千多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为新北企业提供专业的成都网站设计、网站制作、外贸营销网站建设,新北网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。
点击上传
只能上传jpg/png文件,且不超过500kb
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上传图片的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
网站栏目:怎么在vue中使用el-upload上传图片
文章分享:
http://wtcwzsj.com/article/pcdeij.html