element-ui upload组件--多行需要上传文件,该怎么绑定到对应正确的行

如上图所示,点击新增添加多行,每一行都需要上传一个附件,怎么操作才能让上传的附件属于自己那一行,直接上代码


      <el-row>
        <el-col :span="6" style="margin-left: 20px">归属部门</el-col>
        <el-col :span="6">金额</el-col>
        <el-col :span="4">附件</el-col>
        <el-col :span="6">备注</el-col>
      </el-row>


      <el-row  style="margin: 20px 0" v-for="(item,key) in allocateDetail" :key="key">
        <el-col :span="6" style="margin-left: 20px">
          <i
            class="el-icon-remove-outline delete f18"
            @click="delAllocateDetail(key)"
          ></i>
          <el-input v-model="item.deptName" @click.native="feeDeptInfo(key)" style="width: 300px"></el-input>
        </el-col>
        <el-col :span="6">
          <el-input v-model="item.fee" style="width: 300px" @blur="waitAllocateFee"></el-input>
        </el-col>
        <el-col :span="4">
          <el-upload
            :action="uploadUrl"
            ref="upload"
            :before-upload="beforeAvatarUpload"
            :on-success="(res,file) =>{return handleSuccess(res,file,key)}"
            :on-change="handleChange"
            :on-remove="(file) =>{return handleRemove(file,key)}"
            :limit="1"
          >
            <el-button slot="trigger" size="small" type="text">上传附件</el-button>
          </el-upload>
        </el-col>
        <el-col :span="6">
          <el-input v-model="item.remark" style="width: 300px"></el-input>
        </el-col>
        <el-col>
          <div style="height: 5px"></div>
        </el-col>
      </el-row>

添加的数据定义如下,这是data中的数据。allocateDetail是一个数组,里面存放的是一个个item json对象:

allocateDetail: [],
        item:{
          deptId:'',
          deptName:'',
          fee:0,
          attachementPath:'',
          remark:''
        },

点击新增按钮,添加一行的代码如下:

<el-button type="primary" @click="addAllocateDetail()" style="margin-bottom: 15px" size="mini">新增</el-button>

addAllocateDetail() {
        this.allocateDetail.push(
          JSON.parse(JSON.stringify(this.item))
        );
      }

移除一行的代码如下:

delAllocateDetail(key) {
        this.allocateDetail.splice(key, 1);
        this.waitAllocateFee()
      },

element-ui的on-success函数定义如下,key就是使用v-for添加行时,绑定的key:

:on-success="(res,file) =>{return handleSuccess(res,file,key)}"

//监听图片上传成功的事件
      handleSuccess(response,file,key){
        console.log(response)
        console.log("add当前行数:"+key)
        const path = response.result.url
        this.allocateDetail[key].attachementPath = path
      }

element-ui的on-remove函数,删除文件的代码如下:

:on-remove="(file) =>{return handleRemove(file,key)}"

handleRemove(file,key){
        console.log("remove当前行数" +key)
        //console.log(file)
        this.allocateDetail[key].attachementPath = ''
      },

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值