admin管理员组文章数量:1356431
How to take data from v-model array in input type="file" multiple ?
<input type="file" multiple v-model="modFiles[index]">
<input type="file" multiple v-model="modFiles[index]">
<input type="file" multiple v-model="modFiles[index]">
I'm using v-for loop and I can get the first data from each modFiles[].
this.modFiles[0] //take the first from multiple file
But it's only the first data. How can I take all the data inside modFiles[0],modFiles[1],modFiles[3] ? And how to count the data inside each modFiles ?
this.modFiles[0].length //i get error here
thanks so much
How to take data from v-model array in input type="file" multiple ?
<input type="file" multiple v-model="modFiles[index]">
<input type="file" multiple v-model="modFiles[index]">
<input type="file" multiple v-model="modFiles[index]">
I'm using v-for loop and I can get the first data from each modFiles[].
this.modFiles[0] //take the first from multiple file
But it's only the first data. How can I take all the data inside modFiles[0],modFiles[1],modFiles[3] ? And how to count the data inside each modFiles ?
this.modFiles[0].length //i get error here
thanks so much
Share Improve this question asked Feb 2, 2018 at 12:33 brycodebrycode 311 gold badge1 silver badge2 bronze badges1 Answer
Reset to default 5Bidirectional binding is not supported for <input type="file">
, since you're not allowed to set value on such inputs (value is only set after user chooses a file).
Use @change
event instead:
<input type="file" multiple @change="handleFileChange($event, index)">
methods: {
handleFileChange(evt, index) {
// evt.target.files contains Array-like FileList object
}
}
Update:
In order to show/hide your submit button based on count of selected files, introduce new data property:
data: {
filesSelected: 0
},
methods: {
handleFileChange(evt, index) {
this.filesSelected = evt.target.files.length;
}
}
And then use it in your template:
<input type="submit" v-show="filesSelected > 0" />
本文标签: javascriptvmodel on input type files vuejsStack Overflow
版权声明:本文标题:javascript - v-model on input type files vue.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744009061a2575229.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论