element-ui upload使用经验总结

结构:
class="upload-demo"
                    drag
                    name="file"
                    action=""
                    accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                    :before-upload="uploadFile"
                    multiple>
                class="el-icon-upload">
                
class="el-upload__text clearfix">class="fl">将文件拖拽至此区域上传class="fl">点击上传
方法调用: uploadFile(file){ var formData=new FormData(); formData.append('file',file); var file = formData; this.axios.post("/employees/import/upload",file).then((res)=>{ if(res.data.code == 200){ this.$message({ message:"上传成功", type:'success' }) setTimeout(() => { this.$router.push("/lists") },1000) }else if(res.data.code == 401) { this.$message({ message:'会话过期,请重新登录', type:'error' }) localStorage.clear(); sessionStorage.clear(); setTimeout(() => { this.indexUrl(); },400) }else{ this.$message({ message:res.data.msg, type:'error' }) } }) return false; },

你可能感兴趣的:(vue,js)