<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        element-ui實現導入導出

        來源:懂視網 責編:小采 時間:2020-11-27 19:55:03
        文檔

        element-ui實現導入導出

        element-ui實現導入導出:這次給大家帶來element-ui實現導入導出,element-ui實現導入導出的注意事項有哪些,下面就是實戰案例,一起來看一下。前言 眾所周知,ElementUI,是一個比較完善的UI庫,但是使用它需要有一點vue的基礎。在開始本文的正文之前,我們先來看看安裝的方法吧。 安
        推薦度:
        導讀element-ui實現導入導出:這次給大家帶來element-ui實現導入導出,element-ui實現導入導出的注意事項有哪些,下面就是實戰案例,一起來看一下。前言 眾所周知,ElementUI,是一個比較完善的UI庫,但是使用它需要有一點vue的基礎。在開始本文的正文之前,我們先來看看安裝的方法吧。 安

        這次給大家帶來element-ui實現導入導出,element-ui實現導入導出的注意事項有哪些,下面就是實戰案例,一起來看一下。

        前言

        眾所周知,ElementUI,是一個比較完善的UI庫,但是使用它需要有一點vue的基礎。在開始本文的正文之前,我們先來看看安裝的方法吧。

        安裝ElementUI模塊

        cnpm install element-ui -S

        在main.js中引入

        import ElementUI from 'element-ui'
        import 'element-ui/lib/theme-default/index.css'

        全局安裝

        Vue.use(ElementUI)

        當我們安裝完記得重新運行,cnpm run dev ,現在就可以直接使用elementUI了。

        vue + element-ui導入導出功能

        1.前段后臺管理系統中數據展示一般都是用表格,表格會涉及到導入和導出;

        2.導入是利用element-ui的Upload 上傳組件;

        <el-upload class="upload-demo"
         :action="importUrl"//上傳的路徑
         :name ="name"//上傳的文件字段名
         :headers="importHeaders"//請求頭格式
         :on-preview="handlePreview"//可以通過 file.response 拿到服務端返回數據
         :on-remove="handleRemove"//文件移除
         :before-upload="beforeUpload"//上傳前配置
         :on-error="uploadFail"//上傳錯誤
         :on-success="uploadSuccess"//上傳成功
         :file-list="fileList"//上傳的文件列表
         :with-credentials="withCredentials">//是否支持cookie信息發送
        </el-upload>

        3.導出是利用file的一個對象blob;通過調用后臺接口拿到數據,然后用數據來實例化blob,利用a標簽的href屬性鏈接到blob對象

         export const downloadTemplate = function (scheduleType) {
         axios.get('/rest/schedule/template', {
         params: {
         "scheduleType": scheduleType
         },
         responseType: 'arraybuffer'
         }).then((response) => {
         //創建一個blob對象,file的一種
         let blob = new Blob([response.data], { type: 'application/x-xls' })
         let link = document.createElement('a')
         link.href = window.URL.createObjectURL(blob)
         //配置下載的文件名
         link.download = fileNames[scheduleType] + '_' + response.headers.datestr + '.xls'
         link.click()
         })
         }

        4.貼上整個小demo的完整代碼,在后臺開發可以直接拿過去用(vue文件)

        <template>
        <p>
         <el-table
         ref="multipleTable"
         :data="tableData3"
         tooltip-effect="dark"
         border
         style="width: 80%"
         @selection-change="handleSelectionChange">
         <el-table-column
         type="selection"
         width="55">
         </el-table-column>
         <el-table-column
         label="日期"
         width="120">
         <template slot-scope="scope">{{ scope.row.date }}</template>
         </el-table-column>
         <el-table-column
         prop="name"
         label="姓名"
         width="120">
         </el-table-column>
         <el-table-column
         prop="address"
         label="地址"
         show-overflow-tooltip>
         </el-table-column>
         </el-table>
         <p style="margin-top: 20px">
         <el-button @click="toggleSelection([tableData3[1], tableData3[2]])">切換第二、第三行的選中狀態</el-button>
         <el-button @click="toggleSelection()">取消選擇</el-button>
         <el-button type="primary" @click="importData">導入</el-button>
         <el-button type="primary" @click="outportData">導出</el-button>
         </p>
         <!-- 導入 -->
         <el-dialog title="導入" :visible.sync="dialogImportVisible" :modal-append-to-body="false" :close-on-click-modal="false" class="dialog-import">
         <p :class="{'import-content': importFlag === 1, 'hide-dialog': importFlag !== 1}">
         <el-upload class="upload-demo"
         :action="importUrl"
         :name ="name"
         :headers="importHeaders"
         :on-preview="handlePreview"
         :on-remove="handleRemove"
         :before-upload="beforeUpload"
         :on-error="uploadFail"
         :on-success="uploadSuccess"
         :file-list="fileList"
         :with-credentials="withCredentials">
         <!-- 是否支持發送cookie信息 -->
         <el-button size="small" type="primary" :disabled="processing">{{uploadTip}}</el-button>
         <p slot="tip" class="el-uploadtip">只能上傳excel文件</p>
         </el-upload>
         <p class="download-template">
         <a class="btn-download" @click="download">
         <i class="icon-download"></i>下載模板</a>
         </p>
         </p>
         <p :class="{'import-failure': importFlag === 2, 'hide-dialog': importFlag !== 2}" >
         <p class="failure-tips">
         <i class="el-icon-warning"></i>導入失敗</p>
         <p class="failure-reason">
         <h4>失敗原因</h4>
         <ul>
         <li v-for="(error,index) in errorResults" :key="index">第{{error.rowIdx + 1}}行,錯誤:{{error.column}},{{error.value}},{{error.errorInfo}}</li>
         </ul>
         </p>
         </p>
         </el-dialog>
         <!-- 導出 -->
        </p>
        </template>
        <script>
        import * as scheduleApi from '@/api/schedule'
        export default {
         data() {
         return {
         tableData3: [
         {
         date: "2016-05-03",
         name: "王小虎",
         address: "上海市普陀區金沙江路 1518 弄"
         },
         {
         date: "2016-05-02",
         name: "王小虎",
         address: "上海市普陀區金沙江路 1518 弄"
         },
         {
         date: "2016-05-04",
         name: "王小虎",
         address: "上海市普陀區金沙江路 1518 弄"
         },
         {
         date: "2016-05-01",
         name: "王小虎",
         address: "上海市普陀區金沙江路 1518 弄"
         },
         {
         date: "2016-05-08",
         name: "王小虎",
         address: "上海市普陀區金沙江路 1518 弄"
         },
         {
         date: "2016-05-06",
         name: "王小虎",
         address: "上海市普陀區金沙江路 1518 弄"
         },
         {
         date: "2016-05-07",
         name: "王小虎",
         address: "上海市普陀區金沙江路 1518 弄"
         }
         ],
         multipleSelection: [],
         importUrl:'www.baidu.com',//后臺接口config.admin_url+'rest/schedule/import/'
         importHeaders:{
         enctype:'multipart/form-data',
         cityCode:''
         },
         name: 'import',
         fileList: [],
         withCredentials: true,
         processing: false,
         uploadTip:'點擊上傳',
         importFlag:1,
         dialogImportVisible:false,
         errorResults:[]
         };
         },
         methods: {
         toggleSelection(rows) {
         if (rows) {
         rows.forEach(row => {
         this.$refs.multipleTable.toggleRowSelection(row);
         });
         } else {
         this.$refs.multipleTable.clearSelection();
         }
         },
         handleSelectionChange(val) {
         //復選框選擇回填函數,val返回一整行的數據
         this.multipleSelection = val;
         },
         importData() {
         this.importFlag = 1
         this.fileList = []
         this.uploadTip = '點擊上傳'
         this.processing = false
         this.dialogImportVisible = true
         },
         outportData() {
         scheduleApi.downloadTemplate()
         },
         handlePreview(file) {
         //可以通過 file.response 拿到服務端返回數據
         },
         handleRemove(file, fileList) {
         //文件移除
         },
         beforeUpload(file){
         //上傳前配置
         this.importHeaders.cityCode='上海'//可以配置請求頭
         let excelfileExtend = ".xls,.xlsx"//設置文件格式
         let fileExtend = file.name.substring(file.name.lastIndexOf('.')).toLowerCase();
         if (excelfileExtend.indexOf(fileExtend) <= -1) {
         this.$message.error('文件格式錯誤')
         return false
         }
         this.uploadTip = '正在處理中...'
         this.processing = true
         },
         //上傳錯誤
         uploadFail(err, file, fileList) {
         this.uploadTip = '點擊上傳'
         this.processing = false
         this.$message.error(err)
         },
         //上傳成功
         uploadSuccess(response, file, fileList) {
         this.uploadTip = '點擊上傳'
         this.processing = false
         if (response.status === -1) {
         this.errorResults = response.data
         if (this.errorResults) {
         this.importFlag = 2
         } else {
         this.dialogImportVisible = false
         this.$message.error(response.errorMsg)
         }
         } else {
         this.importFlag = 3
         this.dialogImportVisible = false
         this.$message.info('導入成功')
         this.doSearch()
         }
         },
         //下載模板
         download() {
         //調用后臺模板方法,和導出類似
         scheduleApi.downloadTemplate()
         },
         }
        };
        </script>
        <style scoped>
        .hide-dialog{
         display:none;
        }
        </style>

        5.js文件,調用接口

        import axios from 'axios'
        // 下載模板
         export const downloadTemplate = function (scheduleType) {
         axios.get('/rest/schedule/template', {
         params: {
         "scheduleType": scheduleType
         },
         responseType: 'arraybuffer'
         }).then((response) => {
         //創建一個blob對象,file的一種
         let blob = new Blob([response.data], { type: 'application/x-xls' })
         let link = document.createElement('a')
         link.href = window.URL.createObjectURL(blob)
         link.download = fileNames[scheduleType] + '_' + response.headers.datestr + '.xls'
         link.click()
         })
         }

        相信看了本文案例你已經掌握了方法,更多精彩請關注Gxl網其它相關文章!

        推薦閱讀:

        Angular驗證功能實現步奏

        JS實現單例模式的步奏詳解

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        element-ui實現導入導出

        element-ui實現導入導出:這次給大家帶來element-ui實現導入導出,element-ui實現導入導出的注意事項有哪些,下面就是實戰案例,一起來看一下。前言 眾所周知,ElementUI,是一個比較完善的UI庫,但是使用它需要有一點vue的基礎。在開始本文的正文之前,我們先來看看安裝的方法吧。 安
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 国产精品入口麻豆免费观看| 美女在线视频观看影院免费天天看| 国产黄色免费网站| 亚洲AV色香蕉一区二区| 久久国产免费观看精品| 久久国产精品亚洲一区二区| 黄网站色视频免费在线观看的a站最新 | 成人无遮挡裸免费视频在线观看| 亚洲精品91在线| 成人奭片免费观看| 亚洲AV无码片一区二区三区 | 337p日本欧洲亚洲大胆艺术| 精品无码AV无码免费专区| 亚洲春色另类小说| 成人免费无码大片a毛片软件| 欧洲亚洲综合一区二区三区 | 久久精品国产亚洲av成人| 久热免费在线视频| 亚洲国产成人手机在线电影bd| 好爽…又高潮了毛片免费看| 美女被爆羞羞网站在免费观看 | 国产一卡2卡3卡4卡无卡免费视频 国产一卡二卡3卡四卡免费 | 国产成人无码免费视频97 | 99re这里有免费视频精品| 亚洲国产午夜精品理论片| 影音先锋在线免费观看| 免费人成动漫在线播放r18| 亚洲熟妇av一区二区三区| 少妇太爽了在线观看免费视频 | 日韩在线天堂免费观看| 一级毛片免费播放试看60分钟| 亚洲av中文无码乱人伦在线r▽ | 2022免费国产精品福利在线| 亚洲色图国产精品| 在线A级毛片无码免费真人| 精品多毛少妇人妻AV免费久久| 亚洲jjzzjjzz在线播放| 亚洲AⅤ永久无码精品AA| 日韩免费高清大片在线| 亚洲精品久久无码| 亚洲国语精品自产拍在线观看|