善护念兮

VUE,excel 流文件上传

html 页面
<el-upload ref="upload" action :auto-upload="true" :show-file-list="false" :limit="1" :on-exceed="hEc" :http-request="uAPF" :before-upload="beforeUpload" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" :file-list="APFL" :on-change="hAPC" > <el-button slot="trigger" :loading="UP" type="success" size="small" >点击</el-button> </el-upload>

数据段

      APFL: [],
      UP: false,

函数段

 //检查数量
hEc() {
this.$message.error("一次只能上传一个哦"); },
//检测是否是符合规则的文件 beforeUpload(file) {
var suff = file.name.substring( file.name.lastIndexOf(".") + 1, file.name.length ); var isExcel = true; if (suff !== "xlsx" && suff !== "xls") { this.$message({ message: "Please upload the correct Excel!", type: "warning", duration: 2000, }); isExcel = false; } return isExcel; },
hAPC(file, fileList) {
this.APFL = fileList; },
uAPF(file) {
this.UP = true; var formData = new FormData(); formData.append("excel", file.file); importList(formData) .then((res) => { this.UP = false; if (res.status === true) { this.$message({ type: "success", message: "上传成功", duration: 3000, }); this.APFL = []; } }) .catch(() => { // console.log("err", err); this.APFL = []; this.UP = false; }); },

这个方法是直接上传文件的,如果要加其他内容,分开写。

posted on 2020-09-07 15:07  善护念兮  阅读(730)  评论(0编辑  收藏  举报

导航