1

I'm using vue.js and element-ui.

I'd like to use the upload-file component to send files to my server.

I want to stop loading a file to the server, if such file already exists. I want to use the claimed method abort or clearFiles, but can't. What's my mistake?

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!
2
  • What is the error? Commented Sep 3, 2018 at 6:42
  • @franiis, "vue.js:6 ReferenceError: clearFiles is not defined" Commented Sep 3, 2018 at 10:59

1 Answer 1

7

With refs! add ref attribute to el-upload

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

Then call via $refs object

this.$refs.upload.clearFiles()
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, thanks, but what about abort() ? It's not work, fileList not updated.
in case someone finds this 1 year later like me: fileList just holds the default values NOT the files you upload. clearFiles() seems to just clean up the UI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.