我正在使用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!

最佳答案

与裁判!
将ref属性添加到el-upload

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


然后通过$ refs对象调用

this.$refs.upload.clearFiles()

07-24 18:49
查看更多