vue 获取index

夜深了。我直接贴代码吧,好困- -

  <el-upload
    v-for="(item, key, index) in tags"
    :key="item+key+index"
    class="avatar-uploader"
    action="http://upload-z2.qiniu.com/"
    :show-file-list="false"
    :on-success="handleAvatarSuccess"
    :data="qiniuToken"
  >
    <img v-if="imageUrl" :src="imageUrl" class="avatar">
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload>

js

data() {
    return {
        imageUrl: '',
        qiniuToken: {
            token: ''
        }
    }
},
methods: {
    //想知道触发了哪个el-upload,想获取下标
    handleAvatarSuccess(res, file, fileList) {
      console.log(res,'res', fileList, 'fileList',file, 'file')
      // console.log(index,'index')
      this.imageUrl = URL.createObjectURL(file.raw);
    }
}

想知道触发了哪个el-upload,想获取index,大概的需求就是这样子。
el-upload文档

阅读 8k
3 个回答
:on-success="handleAvatarSuccess.bind(null, index)
handleAvatarSuccess(index, res, file, fileList) 
:on-success="handleAvatarSuccess"    //默认res, file, fileList 三个参数

* 想要把 index 在传进去
:on-success="(res, file, fileList ) => handleAvatarSuccess(res, file, fileList , index)"

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题