vue+elementUI实现图片上传不显示添加按钮

news/2025/2/21 17:05:41

先上效果图:

HTML代码:

<div class="grid-content bg-purple" style="text-align: center;">

                      <el-upload

                        action="https://jsonplaceholder.typicode.com/posts/"

                        list-type="picture-card"

                        :class="{hide:hideUpload}"

                        :on-preview="handlePictureCardPreview"

                        :on-remove="handleRemove"

                        :before-upload="beforeAvatarUpload"

                        :on-change="changeimg"

                        :limit="1"

                      >

                        <i class="el-icon-plus"></i>

                      </el-upload>

                      <el-dialog :visible.sync="dialogVisible">

                        <img width="100%" :src="dialogImageUrl" alt />

                      </el-dialog>

                      <div>

                        <span>上传头像</span>

                      </div>

                      <div>

                        <span>只支持JPG、PNG、大小不超过5M</span>

                      </div>

                    </div>

JS代码:

//图片上传

    handleRemove(file, fileList) {

      console.log(file, fileList);

      this.hideUpload = fileList.length >= this.limitCount;

    },

    handlePictureCardPreview(file) {

      this.dialogImageUrl = file.url;

      this.dialogVisible = true;

    },

    changeimg(file, fileList) {

      this.hideUpload = fileList.length >= this.limitCount;

    },

    beforeAvatarUpload(file) {

      const isJPG = file.type === "image/jpeg";

      const isPNG = file.type === "image/png";

      const isLt2M = file.size / 1024 / 1024 < 5;

 

      if (!(isJPG || isPNG)) {

        this.$message.error("上传头像图片只能是 JPG 格式!");

      }

      if (!isLt2M) {

        this.$message.error("上传头像图片大小不能超过 5MB!");

      }

      return (isJPG || isPNG) && isLt2M;

    }

CSS部分

<style>

.hide .el-upload--picture-card {

  display: none;

}

</style>

limitCount是上传数量,我这里指定了1张,那么上传一张就隐藏了添加按钮,如果是需要上传2张之后再隐藏只需要改成2就OK了


http://www.niftyadmin.cn/n/825464.html

相关文章

vue框架跨域问题

这里我是试用了代理方式 在config包下的index.js中配置proxyTable api文件接口以自己配置的/api开头 请求的接口会转成自己的地址是正常的也就相当于后端的域名

vue elementUI 高德地图接口实现省市区街道四级联动

先看看效果图&#xff1a; 这里我使用的是直接get方式去高德去接口数据的方式&#xff0c;所以不需要在vue安装任何东西。 这里不要使用代理跨域&#xff0c;直接把高德地址放上去就行了&#xff0c;key是高德注册的key&#xff0c;后面的参数是用来传递subdistrict&#xff08…

解决vue引入组件报错,和调用组件步骤及封装步骤

这里调用了组件然后报错Unknown custom element: <myAddress> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 讲的是调用<myAddress>组件找不到&#xff0c;那么就是我引入组件的地…

div从上到下从左到右自动换行显示排列

先看效果图&#xff1a; .box{//外部的div盒子 display: flex;//先设置div里的内容显示同一行 justify-content: flex-start;//左右布局 flex-wrap: wrap;//换行 align-content: flex-start;//紧揍排列 } .child1 ,.child2{//div里的内容块 width: 100px; height: …

DatePicker日期限制时间段

1.只能选择当前及以后的日期 <el-date-pickerv-model"value1"type"date":picker-options"pickerOptions"> </el-date-picker>data() {return {pickerOptions: {disabledDate(time) {return time.getTime() < Date.now() - 8.64e7…

地铁框架保护的原理_“开往春天的地铁”需要更多宽容与理解

1月1日,历时三年多的建设,济南轨道交通R1号线正式开通试运行,结束了济南没有地铁的历史,这趟被称为“开往春天的地铁”承载了泉城市民多年的期盼与等待,然而开通后却也遭到了一些戏谑与嘲讽。“第一条从郊区开往郊区的地铁”“成功避开城区所有核心区域与繁华路段”“大批市民开…

hadoop合并日志_hadoop面试题!这6个!经常问!

您是否很快准备接受面试并需要了解Hadoop&#xff1f;不要惊慌&#xff01;以下是您有可能会被问到的一些问题以及我为您提供的答案。 希望对你有帮助哦&#xff01; 正 文 来 啦 问题一&#xff1a;什么是Hadoop&#xff1f;Hadoop是一个开源软件框架&#xff0c;用…

element输入框限制内容为整数

οninput"valuevalue.replace(/[^\d]/g,)"