1

https://github.com/ElemeFE/element http://element.eleme.io/#/en-US/component/upload

<el-upload
  class="avatar-uploader"
  action="/upload"
  :show-file-list="false"
  :on-error="handleUrlError"
  :on-success="handleUrlSuccess">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>

功能:

handleUrlSuccess(response, file, fileList) {
}

如果添加一个额外的参数:

<el-upload
  class="avatar-uploader"
  action="/upload"
  :show-file-list="false"
  :on-error="handleUrlError"
  :on-success="handleUrlSuccess(response, file, fileList, 233)">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>

功能:

handleUrlSuccess(response, file, fileList, param) {
}

属性或方法“响应”未在实例上定义,但在渲染期间引用。

4

1 回答 1

0

您的方法的参数来自组件发出的成功事件。例如,它会有类似的东西

this.$emit('on-success', response, file, fileList)

在内部,Vue 会做类似的事情(这非常简化)......

let boundEventHandler = parseEventHandlerExpression(eventName)
boundEventFunction.apply(vmInstance, arguments)

你可以在你的消费者中做的是捕获所有这些参数,然后附加你自己的

:on-success="handleUrlSuccess(...arguments, 233)"

或者

:on-success="(res, file, fileList) => handleUrlSuccess(res, file, fileList, 233)"

感谢woki最后一个

于 2018-06-28T01:33:02.047 回答