白瑕 2022-04-16 13:48 采纳率: 80%
浏览 1003
已结题

el-upload无法获取fileList

在onchange事件时输出fileList, 结果为undefined.
问题相关代码,请勿粘贴截图
<template>
  <el-upload
    action="https://jsonplaceholder.typicode.com/posts/"
    :show-file-list="true"
    :on-change="onchange()"
    :before-upload="onchange()"
    :auto-upload="false"
    ref="upload"
    :file-list="data.fileList"
  >
    <template v-slot:trigger>
      <el-button type="primary">选择文件</el-button>
    </template>
    <el-button class="ml-3" type="success" @click="submit"> 上传 </el-button>
    <template v-slot:tip>
      <div class="el-upload__tip text-red">
        limit 1 file, new file will cover the old file
      </div>
    </template>
  </el-upload>
</template>
import { ref, reactive } from "vue";
const upload = ref(null);

export default {
  setup() {
    let data = reactive({
      fileList: [],
    });

    const onchange = (file, fileList) => {
      console.log(file);
      console.log(fileList);
    };

    return {
      data,
      onchange,
      upload
    };
  },
};
运行结果及报错内容

img

感谢
  • 写回答

2条回答 默认 最新

  • zh阿飞 2022-04-16 22:38
    关注

    这两个重了

    :on-change="onchange()"
    :before-upload="onchange()"
    

    img

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月16日
  • 已采纳回答 6月8日
  • 创建了问题 4月16日

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!