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; }); },

這個方法是直接上傳文件的,如果要加其他內容,分開寫。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM