admin 管理员组文章数量: 1086019
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()
本文标签: javascriptVuejsElementui Upload how call method ClearFiles or AbortStack Overflow
版权声明:本文标题:javascript - Vue.js + Element-ui Upload: how call method ClearFiles or Abort - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744017900a2519260.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论