语法
<input type="file" accept="image/*" mutiple="mutiple" capture="camera" />
三个属性:
accept - 规定可提交的文件类型。
capture - 系统所捕获的默认设备。camera(照相机),camcorder(摄像机),microphone(录音)
mutiple - 支持多选。当支持多选时,multiple优先级高于capture。
几种写法:
<input type="file" accept="image/*" mutiple="mutiple" capture="camera" />
<input type="file" name="upload" accept="image/png,image/jpeg,image/gif" capture="camera">
<input type="file" accept=".gif,.jpg,.png,.jpeg,.bmp" name="file" />
<input type="file" accept="image/*" capture="camera">
<input type="file" accept="video/*" capture="camcorder">
<input type="file" accept="audio/*" capture="microphone">
<input type="file" accept="image/*" >
<input type="file" accept="video/*" >
<input type="file" accept="audio/*" >
上传身份证正反面实例
<div class="center">
<input type="file" class="input-file" name="picture" ref="pictureFront" id="pictureFront"
@change="changeImage($event,'front')"
style="position: absolute;z-index: -1;left:-100%;opacity: 0"
accept="image/*"/>
<div @click="focus('pictureFront')" class="image">
<img v-if="picData.front" :src="picData.front" alt="">
<i v-else class="iconfont icon-shenfenzhengzhengmian"></i>
<div v-if="!picData.front">点击上传</div>
</div>
</div>
changeImage (e, type) {
const file = e.target.files[0];
if (file) {
this.fileData[type] = file;
const reader = new FileReader();
const that = this;
reader.readAsDataURL(file);
reader.onload = function (e) {
that.picData[type] = this.result;
focus (type) {
this.$refs[type].click();
参考:原文链接