700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > element-ui的upload 上传组件 照片墙当超过限定图片后隐藏上传按钮

element-ui的upload 上传组件 照片墙当超过限定图片后隐藏上传按钮

时间:2022-10-01 14:42:00

相关推荐

element-ui的upload 上传组件 照片墙当超过限定图片后隐藏上传按钮

隐藏上传组件。比如我想限制上传5张 ,上传到第五张后,上传组件隐藏,

<el-uploadaccept=".png, .jpeg, .jpg, .gif":limit="5":action="`${baseApi}/systemController/v1.0/uploadImg`"list-type="picture-card":file-list="fileList":before-upload="uploadEdit":on-success="handlePictureCardPreview":on-remove="handleRemove":on-change="handleEditChange":class="{hide:hideUploadEdit}"><i class="el-icon-plus"></i></el-upload>然后在dataexport default {name: '',data () {return {hideUpload: false,}}}methods: {handleEditChange (file, fileList) {this.hideUploadEdit = fileList.length >= 5},handleRemove (file, fileList) {if (fileList.length === 0) {this.fileList = []} else {let dl = this.fileList.indexOf(file)this.fileList.splice(dl, 1)}this.hideUploadEdit = fileList.length >= 5},handlePictureCardPreview (file) {this.curAskedDetail.asked_imgs = file.datathis.fileList.push({ url: file.data })},uploadEdit (file) {return this.xianZhi(file)},uploadAdd (file) {return this.xianZhi(file)},xianZhi (file) {const isLimit = file.size / 1024 / 1024 <= 5if (['image/jpeg', 'image/jpg', 'image/png', 'image/gif'].indexOf(file.type) === -1) {this.$message.error('上传图片只能是 jpg/jpeg/gif/png格式!')return false}if (!isLimit) {this.$message.error('上传图片大小不能超过" + 5 + "MB!')return false}}}<style>.hide .el-upload--picture-card {display: none;}</style>

注意,必须去掉scoped,不然不生效

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。