File input on change in vue.js(vue.js 中更改的文件输入)
问题描述
Using plain HTML/JS, it is possible to view the JavaScript File objects of selected files for an input element like so:
<input type="file" id="input" multiple onchange="handleFiles(this.files)">
However, when converting it to the 'Vue' way it doesn't seem to work as intend and simply returns undefined
instead of returning an Array of File objects.
This is how it looks in my Vue template:
<input type="file" id="file" class="custom-file-input"
v-on:change="previewFiles(this.files)" multiple>
Where the previewFiles
function is simply the following (located in methods):
methods: {
previewFiles: function(files) {
console.log(files)
}
}
Is there an alternate/correct way of doing this? Thanks
Another solution:
<input type="file" @change="previewFiles" multiple>
methods: {
previewFiles(event) {
console.log(event.target.files);
}
}
这篇关于vue.js 中更改的文件输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:vue.js 中更改的文件输入


基础教程推荐
- Bokeh Div文本对齐 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01