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

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

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


      
        归属部门
        金额
        附件
        备注
      


      
        
          
          
        
        
          
        
        
          
            上传附件
          
        
        
          
        
        
          

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

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

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

新增

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 = ''
      },

 

你可能感兴趣的:(element-ui upload组件--多行需要上传文件,该怎么绑定到对应正确的行)