element-ui upload使用经验总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zfangls/article/details/79280418
结构:
<el-upload
                    class="upload-demo"
                    drag
                    name="file"
                    action=""
                    accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                    :before-upload="uploadFile"
                    multiple>
                <i class="el-icon-upload"></i>
                <div class="el-upload__text clearfix"><span class="fl">将文件拖拽至此区域上传</span><em class="fl">点击上传</em></div>
            </el-upload>
方法调用:
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;
            },
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页