国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

Vue + iView實(shí)現Excel上傳功能的完整代碼

發(fā)布時(shí)間:2021-08-17 12:16 來(lái)源: 閱讀:0 作者:牧馬少女 欄目: JavaScript 歡迎投稿:712375056

1、HTML部分

<Col span="2">上傳文件:</Col>
<Col span="22" class="uploadExcelBox">
    <Upload ref="uploadExcel" :loading="uploadLoading" :action="uploadFileUrl" accept="xlsx,xls" :format="uploadFormat" :before-upload="beforeImgFile" :on-success="successImgFile" :on-error="errorImgFile" :show-upload-list="true">
         <Button type="success">上傳附件</Button>
	 </Upload>
     <div v-if="uploadingFile !== null">待上傳文件:
          <span class="blueFont">{{ fileName }}</span>
          <Button @click="uploadFun(index)" :loading="loadingStatus" class="manualUploadBtn">{{ loadingStatus ? '上傳中...' : '點(diǎn)擊開(kāi)始上傳' }}</Button>
      </div>
</Col>

2、JS部分

<script>
    // import excel from '@/libs/excel'
	import service from '@/libs/request' //用來(lái)取當前域名
	import reportFormApi from '@/api/reportForm'
    export default {
        data() {
            return {
                uploadLoading:false,//上傳控件loading狀態(tài)
				uploadFileUrl: "",
				uploadFormat:['xlsx','xls'],
				uploadingFile:null,//待上傳的文件
                loadingStatus:false,//upload組件的狀態(tài)
                fileName:"",//待上傳文件的名稱(chēng)
            }
        },
        mounted() {
            this.uploadFileUrl = service.apiUrl + "/qingximaster/winInfo/execlAdd";//上傳Excel的接口路徑,后端人員提供。
        },
        methods: {
			// 圖片上傳之前
			beforeImgFile(file) {
				// console.log(file);
				const fileExt = file.name.split('.').pop().toLocaleLowerCase()
				if (fileExt === 'xlsx' || fileExt === 'xls') {
					var formdata = new FormData();
					formdata.append("file",file);
                    this.fileName = formdata.get('file').name;//通過(guò)formdata.get('file')方法,可以取file文件里的信息,例如Excel的文件名。
					this.uploadingFile =  formdata;//注意:這個(gè)將作為參數傳給接口實(shí)現上傳。傳給接口的file不需要 formdata.get('file'),直接傳file。
				} else {
					this.$Notice.warning({
						title: '文件類(lèi)型錯誤',
						desc: '文件:' + file.name + '不是EXCEL文件,請選擇后綴為.xlsx或者.xls的EXCEL文件。'
					})
				}
				return false
			},
			// 上傳成功
			successImgFile(response, file, fileList) {
                this.$Notice.success({
                    title: '提示',
                    desc: '上傳成功!'
                })
			},
			// 上傳失敗
			errorImgFile(error, file, fileList) {
				this.$Notice.success({
                    title: '提示',
                    desc: '上傳失??!'
                })
				console.log(error);
			},
			uploadFun(index){//調接口上傳Excel
				this.loadingStatus = true;
				reportFormApi.uploadExcel({
                    url: this.uploadFileUrl,
                    file: this.uploadingFile
                }).then(res =>{
					this.uploadingFile = null;
                    this.fileName = "";
                    if(res.code==0){
                        this.infoList[index].content = JSON.stringify(res.data);
					    // console.log(this.infoList[index].content);
                        this.$Message.success("上傳成功!");
                    }else{
                        this.$Message.error(res.message);
                    }
				}).finally(()=>{
					this.loadingStatus = false;
                    this.uploadLoading = false;
                })
			},
        }
    }

3、頁(yè)面效果如下

(1)進(jìn)入頁(yè)面默認展示的樣子

 (2)選中要上傳的Excel

 (3)“點(diǎn)擊開(kāi)始上傳”之后

 

以上就是Vue + iView實(shí)現Excel上傳的詳細內容,更多關(guān)于vue iview excel上傳的資料請關(guān)注腳本之家其它相關(guān)文章!

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

国产男女免费完整视频| 99精品免视看| 国产无线乱码一区二三区| 卡一卡二卡三精品| 久久综合九色综合欧美就去吻| 亚洲AV无码久久精品色欲|