前端开发动态控制ui框架的class类名(elementUI上传组件限制数量后去掉上传按钮)

动态控制ui框架的class类名

给需要控制的类名嵌套类名

elementUI 上传组件示例代码
<el-upload
  :class="{uploadDemo:isHide}" //动态控制类名的关键isHide
  action="https://jsonplaceholder.typicode.com/posts/"
  :file-list="fileList"
  :on-remove="handleRemove" //删除时的钩子
  :on-change="handleChange" //上传的文件变化时的钩子
  :limit="3" //限制上传数量为3
>
  <template v-slot:tip>
    <div class="el-upload__tip">文件不超过3</div>
  </template>
</el-upload>
<script>
  import { reactive, toRefs, getCurrentInstance } from 'vue'
  export default {
  data() {
      return {
        isHide: false,
        fileList: []
      };
    },
    methods: {
    // 在以下两个钩子函数中控制isHide变量
    //文件列表移除文件时的钩子
      handleRemove(file, fileList) {
        console.log(file, fileList);
        if(fileList.length < 3) {
        	this.isHide = false
        } else {
        	this.isHide = true
        }
      },
    //文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用
      handleChange(file, fileList) {
        console.log(file, fileList);
        if(fileList.length < 3) {
        	this.isHide = false
        } else {
        	this.isHide = true
        }
      },
    }
  }
</script>
//通过样式控制上传按钮的隐藏
<style>
.uploadDemo .el-upload--picture-card {
 	display: none;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值