举例:上传头像成功的回调函数,没有自定义的index
改变 :通过在回调函数里定义自己的参数的形式来保留默认参数,同时也可以自己传参数
:on-success="(res,fileList)=>handleAvatarListSuccess(res,fileList,index)"
// res,fileList是:on-success的两个默认参数,index是自定义参数
<el-upload
v-for="(item,index) in 5" :key="item"
class="avatar-uploader"
action="/api/v1/sp-file"
:headers="{'Authorization':authorization}"
:show-file-list="false"
:on-success="(res,fileList)=>handleAvatarListSuccess(res,fileList,index)"
:on-error=handleAvatarErr
:before-upload="beforeAvatarUpload">
js中
handleAvatarListSuccess(res: any, fileList: any, index: any) {
// console.log(fileList, index);
this.$set(this.imageUrlList, index, fileList.response.url);
this.$message({
type: 'success',
message: '上传成功!'
});
}