【问题标题】:Vue.js + Element-ui Upload: how call method ClearFiles or AbortVue.js + Element-ui 上传:如何调用 ClearFiles 或 Abort 方法
【发布时间】:2018-09-03 06:26:48
【问题描述】:

我正在使用vue.jselement-ui

我想使用upload-file 组件将文件发送到我的服务器。

如果该文件已经存在,我想停止将文件加载到服务器。我想使用声称的方法abortclearFiles,但不能。 我的错误是什么?

HTML

<el-upload
     action="",
     :http-request="addAttachment",
     :on-remove="deleteAttachment",
     :before-upload="handleBeforeUpload",
     :file-list="fileList">
</el-upload>
<el-button size="small" type="success" @click="clearFiles">clear</el-button>

JAVASCRIPT

var vm = new Vue({
    data() {
        return {
            fileList: []
        };
    },
    methods: {
        handleBeforeUpload(file) {
            //if loading file exists in fileList - abort 
            if (findIndexInFileList(file) >= 0) {
                clearFiles(); //error
                this.clearFiles(); //.. and error
                vm.clearFiles(); //.. and also error
            }
        }
    }
}).$mount('#app');

vm.clearFiles(); //error!

【问题讨论】:

  • 错误是什么?
  • @franiis, "vue.js:6 ReferenceError: clearFiles is not defined"

标签: javascript upload vuejs2 element-ui


【解决方案1】:

有参考! 添加 ref 属性到 el-upload

<el-upload
 ref="upload">
</el-upload>

然后通过 $refs 对象调用

this.$refs.upload.clearFiles()

【讨论】:

  • 好的,谢谢,但是 abort() 呢?不行,fileList 没有更新。
  • 如果有人像我一样在 1 年后发现这个:fileList 只保存默认值,而不是您上传的文件。 clearFiles() 似乎只是清理 UI
猜你喜欢
  • 2019-02-04
  • 1970-01-01
  • 2017-10-02
  • 2020-01-12
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
  • 2019-10-12
  • 1970-01-01
相关资源
最近更新 更多