vue2 upload多图片上传

dom

   <el-upload
                :class="{ uoloadSty: showBtnImg, disUoloadSty: noneBtnImg }"
                class="avatar-uploader"
                ref="upload" 
                action="#"
                :limit="limitCountImg" //限制上传图片的数量
                :show-file-list="true" //列表展示
                :auto-upload="false" //点击上传
                list-type="picture-card"
                :http-request="handleHttpRequestIcon" //成功
                :on-change="imgChange" //change 
                :on-remove="handleRemove" //删除事件
                accept="image/jpg,image/jpeg,image/png"
              >
                <i class="el-icon-plus"></i>
              </el-upload>

css

::v-deep .el-upload--picture-card {
  width: 100px;
  height: 100px;
  line-height: 100px;
  background: rgba(255, 255, 255, 0.06);
}
::v-deep .el-upload-list__item-actions {
  width: 100px;
  height: 100px;
}
::v-deep .el-upload-list__item-thumbnail {
  width: 100px;
  height: 100px;
  object-fit: cover;
}
::v-deep .el-upload-list__item {
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.06);
}
/* 上传图片时隐藏 */
::v-deep .uoloadSty .el-upload--picture-card {
  width: 100px;
  height: 100px;
  line-height: 100px;
}
::v-deep .disUoloadSty .el-upload--picture-card {
  display: none; /* 上传按钮隐藏 */
}

script

export default{
data(){
retutn{
      showBtnImg: true,
      noneBtnImg: false,
      limitCountImg: 1,
}

},
methods:{
  imgChange(file, fileList) {
      this.noneBtnImg = fileList.length >= this.limitCountImg;
    },
    // 处理删除事件
    handleRemove(file, fileList) {
      // "文件已被删除:", file
      // "当前文件列表:", fileList
      this.noneBtnImg = !fileList.length <= 0;
    },
    addConfirm() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          this.loadingShow = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          this.$refs.upload.submit();
        }
      });
    },
    handleHttpRequestIcon(file) {
      httpIconRequest(file, {
        next: (response) => {
          // console.log(response);
        },
        error: (err) => {
          this.loadingShow.close();
        },
        complete: (res) => {
          this.loadingShow.close();
          this.room.room_avatar = res.key;
        },
      });
    },
}


}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值