vue+el-upload图片上传

在这里插入图片描述

 <el-card style="margin-top:15px">
        <el-tabs type="border-card" v-model="activeName">
          <el-tab-pane
            v-for="(item, index) in chooseList"
            :key="index"
            :label="item.label"
          >
            <div>
              <el-upload
                drag
                action="http://xxx/upload/files"
                :headers="headers"
                :on-success="uploadSuccess1"
                :on-preview="handlePreview1"
                :on-remove="handleRemove1"
                :before-remove="beforeRemove1"
                multiple
                :limit="5"
                :file-list="item.fileList"
              >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">点击或将文件拖拽到这里上传</div>
                <div class="el-upload__text">支持扩展名:rar.zip.doc.docx.pdf.jpg</div>
              </el-upload>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-card>
  headers: { "access-token": window.localStorage.getItem("xxx_USER") },
   {
          value: 0,
          label: "xxx",
          fileList: [],
          attachment: [],
        },
        {
          value: 1,
          label: "xxx",
          fileList: [],
          attachment: [],
        },
 uploadSuccess1(response) {
      console.log("上传", response);
      if (response.code == 200) {
        this.chooseList[this.activeName].fileList = response.data.files;
        this.chooseList[this.activeName].fileList.forEach((item) => {
          this.chooseList[this.activeName].attachment.push(item.id);
        });
        this.$message.success("上传成功");
      }
    },
//点击图片,处理图片预览效果
    handlePreview1(file) {
      console.log("handlePreview", file);
      
    },
//删除图片
    handleRemove1(file, fileList) {
      console.log("handleRemove", file, fileList);
      this.chooseList[this.activeName].fileList = fileList;
      // fileList.forEach(item => {
      //   this.addProjectForm.titlepic.push(item.id)
      // })
      this.chooseList[this.activeName].attachment = [];
    },
 beforeRemove1(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}`);
    },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值