Element: Uploder 的钩子能否允许传回自定义参数

Created on 9 Jan 2017  ·  4Comments  ·  Source: ElemeFE/element

ElementUI version

1.1.2

场景是这样的:我在一个页面里使用多个Uploder组件来上传多张图片,
目前只能通过给每个Uploder的on-success钩子绑定一个特定的方法,
代码看起来是这样的,感觉蠢蠢的

idCardSuccess(response, file, fileList){
  this.submiti.idCard=response.data.img
},

bankCardSuccess(response, file, fileList){
  this.submiti.bankCard=response.data.img
}
...

如果可以给钩子传自定义参数,那就爽多了

onSuccess(response, file, fileList, key){
  this.submit[key]=response.data.img
},

Most helpful comment

刚开始使用Element,我遇到了同样的问题,看到这里不得不去gitter,虽然上有人问了,然鹅根本没人回复,最后我自己想出了这种方式实现:

handleSuccess (custom) {
  return (res, file) => {
    custom.fieldA = window.URL.createObjectURL(file.raw)
    console.log('end:', custom)
  }
}

custom就是你自定义的参数,注意如果直接将fieldA作为自定义参数,修改不会生效。
后入坑的童鞋,如果对你有帮助请给个👍

All 4 comments

这个属于最佳实践的问题,可以到giiter询问下

刚开始使用Element,我遇到了同样的问题,看到这里不得不去gitter,虽然上有人问了,然鹅根本没人回复,最后我自己想出了这种方式实现:

handleSuccess (custom) {
  return (res, file) => {
    custom.fieldA = window.URL.createObjectURL(file.raw)
    console.log('end:', custom)
  }
}

custom就是你自定义的参数,注意如果直接将fieldA作为自定义参数,修改不会生效。
后入坑的童鞋,如果对你有帮助请给个👍

@johntostring 太厉害了,解决了我的困扰,不过新手不懂原理

@weiwill 请问怎么解决的额?

Was this page helpful?
0 / 5 - 0 ratings