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
1 Answer
Reset to default 7With refs! add ref attribute to el-upload
<el-upload
ref="upload">
</el-upload>
Then call via $refs object
this.$refs.upload.clearFiles()