最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue.js + Element-ui Upload: how call method ClearFiles or Abort - Stack Overflow

programmeradmin8浏览0评论

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

I'd like to use the upload-file ponent 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!

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

I'd like to use the upload-file ponent 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!
Share Improve this question edited Sep 3, 2018 at 7:11 franiis 1,3761 gold badge19 silver badges33 bronze badges asked Sep 3, 2018 at 6:26 Anna ShAnna Sh 131 silver badge4 bronze badges 2
  • What is the error? – franiis Commented Sep 3, 2018 at 6:42
  • @franiis, "vue.js:6 ReferenceError: clearFiles is not defined" – Anna Sh Commented Sep 3, 2018 at 10:59
Add a ment  | 

1 Answer 1

Reset to default 7

With refs! add ref attribute to el-upload

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

Then call via $refs object

this.$refs.upload.clearFiles()
发布评论

评论列表(0)

  1. 暂无评论