vue中使用input[type="file"]实现文件上传功能
(编辑:jimmy 日期: 2024/11/17 浏览:3 次 )
注意:input[type="file"]
标签中的属性accept="application/msword,application/pdf"
在pc上正常,但是在手机ios和android上这个文件格式限制会被忽略,所以需要在js中增加格式的判断,以及对应显示样式的设置.(我也是刚发现,如果有遇到这个问题的可以参考下---下面有更改:)
```
<template> <div id="my-careers"> <head-top id="header"> <i slot="left" class="iconfont icon-back"></i> <span slot="title">Apply Online</span> <i slot="right" class="icon-right fa"></i> </head-top> <div class="content"> <form @submit.prevent="onSubmit" id="fileForm" > <div class="form"> <h3>Customer Car Manager</h3> <ul class="form-group"> <li class="info-name"> <input type="text" v-focus :class="{errli:form.nameErr}" name="name" placeholder="Name" v-model="applyInfo.name" > <p class="errP" v-if="form.nameErr">{{form.nameMsg}}</p> </li> <li class="info-email"> <input type="text" :class="{errli:form.emailErr}" name="email" placeholder="Email Address" v-model="applyInfo.email" > <p class="errP" v-if="form.emailErr">{{form.emailMsg}}</p> </li> <li class="info-mobile"> <input type="number" :class="{errli:form.mobileErr}" name="mobile" placeholder="Mobile Number" v-model="applyInfo.mobile" > <p class="errP" v-if="form.mobileErr">{{form.mobileMsg}}</p> </li> <li class="info-location"> <input type="text" :class="{errli:form.locationErr}" name="location" placeholder="Current Location" v-model="applyInfo.location" > <p class="errP" v-if="form.locationErr">{{form.locationMsg}}</p> </li> <li class="reason-li" :class="{'info-reason':applyInfo.joinReason.split('').length >= 300}"> <textarea :class="{errli:form.joinReasonErr}" name="joinReason" v-model="applyInfo.joinReason" rows="5" cols="20" placeholder="Why do you want to join HappyEasy Go" ></textarea> <span>{{wordNumber}}</span> <p class="errP" v-if="form.joinReasonErr">{{form.joinReasonMsg}}</p> </li> <li class="info-link"> <input type="text" :class="{errli:form.linkedinUrlErr}" name="linkedinUrl" placeholder="LinkedIn URL (Optional)" v-model="applyInfo.linkedinUrl" > <p class="errP" v-if="form.linkedinUrlErr" >{{form.linkedinUrlMsg}}</p> </li> <li class="info-file" > <span class="file-span" v-if="fileObj != null" v-show="isSelectFile">{{fileObj.name}}</span> <p v-show="!isSelectFile">Attach Resume</p> <p v-show="!isSelectFile">(Microsoft Word or PDF file is allowed (5MB))</p> <p><input type="file" id="upfile" accept="application/msword,application/pdf" name="upfile" @change="selectFile" ><span>Upload file</span> or drag and drop</p> </li> <li class="info-btns flex space-between" > <button @click="infoJustify" :class="{active:true}">Submit</button> </li> </ul> </div> </form> </div> <div class="career-cover" v-show="showDialog"></div> <div class="career-dialog" v-show="showDialog"> <div class="d-top"> Apply Online </div> <div class="d-center"> Thank you for applying to this job! </div> <div class="d-bottom"> <button @click="applySuccess">OK</button> </div> <img :src="/UploadFiles/2021-04-02/dialogBg">总结
以上所述是小编给大家介绍的vue中使用input[type="file"]实现文件上传功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
下一篇:详解Eslint 配置及规则说明