最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iview+vue實(shí)現(xiàn)導(dǎo)入EXCEL預(yù)覽功能

 更新時(shí)間:2022年07月06日 08:32:26   作者:LBJsagiri  
這篇文章主要為大家詳細(xì)介紹了iview+vue實(shí)現(xiàn)導(dǎo)入EXCEL預(yù)覽功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iview+vue實(shí)現(xiàn)導(dǎo)入EXCEL預(yù)覽的具體代碼,供大家參考,具體內(nèi)容如下

Xboot中,前端實(shí)現(xiàn)導(dǎo)入EXCEL預(yù)覽功能

HTML部分

<!-- 導(dǎo)入數(shù)據(jù) -->
? <Drawer title="導(dǎo)入數(shù)據(jù)" closable v-model="importModalVisible" width="1000">
? ? ? <div
? ? ? ? style="
? ? ? ? ? display: flex;
? ? ? ? ? justify-content: space-between;
? ? ? ? ? align-items: center;
? ? ? ? "
? ? ? >
? ? ? ? <Upload ref="upload"
? ? ? ? ? :action="importFile"
? ? ? ? ? :before-upload="beforeUploadImport"
? ? ? ? ? accept=".xls, .xlsx"
? ? ? ? ? :on-success="uploadSucess"
? ? ? ? ? :headers="accessToken">
? ? ? ? ? <Button
? ? ? ? ? ? :loading="reading"
? ? ? ? ? ? icon="ios-cloud-upload-outline"
? ? ? ? ? ? style="margin-right: 10px"
? ? ? ? ? ? >上傳Excel文件</Button
? ? ? ? ? >
? ? ? ? ? <span v-if="uploadfile.name"
? ? ? ? ? ? >當(dāng)前選擇文件:{{ uploadfile.name }}</span
? ? ? ? ? >
? ? ? ? </Upload>
? ? ? ? <Button @click="clearImportData" icon="md-trash">清空數(shù)據(jù)</Button>
? ? ? </div>
? ? ? <Alert type="warning" show-icon
? ? ? ? >導(dǎo)入前請(qǐng)下載查看導(dǎo)入模版數(shù)據(jù)文件查看所需字段及說(shuō)明,確保數(shù)據(jù)格式正確,不得修改列英文名稱(chēng)</Alert
? ? ? >
? ? ? <Table
? ? ? ? :columns="importColumns"
? ? ? ? border
? ? ? ? :data="importTableData"
? ? ? ? ref="importTable"
? ? ? ></Table>
? ? ? <!-- <div class="drawer-footer"> -->
? ? ? ? <div style="position: absolute; right: 15px; display: inline-block">
? ? ? ? ? <Button @click="importModalVisible = false">關(guān)閉</Button>
? ? ? ? ? <Button
? ? ? ? ? ? :loading="importLoading"
? ? ? ? ? ? :disabled="importTableData.length <= 0"
? ? ? ? ? ? @click="importData"
? ? ? ? ? ? style="margin-left: 8px"
? ? ? ? ? ? type="primary"
? ? ? ? ? >
? ? ? ? ? ? 確認(rèn)導(dǎo)入
? ? ? ? ? ? <span v-if="importTableData.length > 0"
? ? ? ? ? ? ? >{{ importTableData.length }} 條數(shù)據(jù)</span
? ? ? ? ? ? >
? ? ? ? ? </Button>
? ? ? ? </div>
? ? ? <!-- </div> -->
</Drawer>

需要引入

1、安裝插件

npm i xlsx

2、引入

import XLSX from "xlsx";

data中定義

importFile: importEquipment,//接口
accessToken: {},
uploadfile: {
??? ?name: ''
},
importColumns: [],
importTableData: [],

js代碼

//導(dǎo)入數(shù)據(jù)
? ? beforeUploadImport(file) {
? ? ? this.uploadfile = file
? ? ? const fileExt = file.name
? ? ? ? .split('.')
? ? ? ? .pop()
? ? ? ? .toLocaleLowerCase()
? ? ? if (fileExt == 'xlsx' || fileExt == 'xls') {
? ? ? ? this.readFile(file)
? ? ? ? this.file = file
? ? ? } else {
? ? ? ? this.$Notice.warning({
? ? ? ? ? title: '文件類(lèi)型錯(cuò)誤',
? ? ? ? ? desc:
? ? ? ? ? ? '所選文件‘ ' +
? ? ? ? ? ? file.name +
? ? ? ? ? ? ' '不是EXCEL文件,請(qǐng)選擇后綴為.xlsx或者.xls的EXCEL文件。'
? ? ? ? })
? ? ? }
? ? ? return false
? ? },
? ? // 讀取文件
? ? readFile(file) {
? ? ? this.reading = true
? ? ? const reader = new FileReader()
? ? ? reader.readAsArrayBuffer(file)
? ? ? reader.onerror = (e) => {
? ? ? ? this.reading = false
? ? ? ? this.$Message.error('文件讀取出錯(cuò)')
? ? ? }
? ? ? reader.onload = (e) => {
? ? ? ? console.log(e.target.result)
? ? ? ? const data = e.target.result
? ? ? ? const { header, results } = excel.read(data, 'array')
? ? ? ? const tableTitle = header.map((item) => {
? ? ? ? ? return { title: item, key: item, minWidth: 130, align: 'center' }
? ? ? ? })
? ? ? ? this.importTableData = results
? ? ? ? this.importColumns = tableTitle
? ? ? ? this.reading = false
? ? ? ? this.$Message.success('讀取數(shù)據(jù)成功')
? ? ? }
? ? },
? ? uploadSucess(response) {
? ? ? if (response.code == 200) {
? ? ? ? this.$Message.success('導(dǎo)入成功')
? ? ? ? this.importModalVisible = false
? ? ? ? this.clearImportData()
? ? ? ? this.getDataList()
? ? ? } else {
? ? ? ? this.$Message.error(response.message)
? ? ? }
? ? ? this.uploadfile = {}
? ? },
? ? clearImportData() {
? ? ? this.importTableData = []
? ? ? this.importColumns = []
? ? ? this.uploadfile = {}
? ? ? this.$refs.upload.clearFiles();
? ? },

導(dǎo)入模板

效果預(yù)覽

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue組件props不同數(shù)據(jù)類(lèi)型傳參的默認(rèn)值問(wèn)題

    vue組件props不同數(shù)據(jù)類(lèi)型傳參的默認(rèn)值問(wèn)題

    這篇文章主要介紹了vue組件props不同數(shù)據(jù)類(lèi)型傳參的默認(rèn)值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • vuex狀態(tài)管理淺談之mapState用法

    vuex狀態(tài)管理淺談之mapState用法

    當(dāng)一個(gè)組件需要獲取多個(gè)狀態(tài)的時(shí)候,將這些狀態(tài)都聲明為計(jì)算屬性會(huì)有些重復(fù)和冗余,為了解決這個(gè)問(wèn)題我們可以使用mapState輔助函數(shù)幫助我們生成計(jì)算屬性,這篇文章主要給大家介紹了關(guān)于vuex狀態(tài)管理之mapState用法的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • ElementUI中el-tree節(jié)點(diǎn)的操作的實(shí)現(xiàn)

    ElementUI中el-tree節(jié)點(diǎn)的操作的實(shí)現(xiàn)

    這篇文章主要介紹了ElementUI中el-tree節(jié)點(diǎn)的操作的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • vue調(diào)用本地?cái)z像頭實(shí)現(xiàn)拍照功能

    vue調(diào)用本地?cái)z像頭實(shí)現(xiàn)拍照功能

    這篇文章主要介紹了vue調(diào)用本地?cái)z像頭實(shí)現(xiàn)拍照功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 如何使用Vue的思想封裝一個(gè)Storage

    如何使用Vue的思想封裝一個(gè)Storage

    作為Web Storage API的接口,Storage 提供了訪問(wèn)特定域名下的會(huì)話存儲(chǔ)或本地存儲(chǔ)的功能,例如可以添加、修改或刪除存儲(chǔ)的數(shù)據(jù)項(xiàng),這篇文章主要給大家介紹了關(guān)于如何使用Vue的思想封裝一個(gè)Storage的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • 使用Vue?控制元素顯示隱藏的方法和區(qū)別

    使用Vue?控制元素顯示隱藏的方法和區(qū)別

    這篇文章主要介紹了Vue??控制元素顯示隱藏的方法和區(qū)別,需要的朋友可以參考下
    2022-12-12
  • Vue3 defineModel的使用示例詳解

    Vue3 defineModel的使用示例詳解

    文章介紹了vue中向子組件傳值并允許修改的機(jī)制,通過(guò)defineModel實(shí)現(xiàn)雙向綁定,它返回一個(gè)ref,并且可以配置底層prop的選項(xiàng),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2025-01-01
  • vue初始化動(dòng)畫(huà)加載的實(shí)例

    vue初始化動(dòng)畫(huà)加載的實(shí)例

    今天小編就為大家分享一篇vue初始化動(dòng)畫(huà)加載的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • vue項(xiàng)目打包部署跨域的實(shí)現(xiàn)步驟

    vue項(xiàng)目打包部署跨域的實(shí)現(xiàn)步驟

    在前端 Vue 項(xiàng)目打包后,如果需要訪問(wèn)另一個(gè)域名下的接口,由于瀏覽器的同源策略限制,會(huì)出現(xiàn)跨域問(wèn)題,本文就介紹一下vue項(xiàng)目打包部署跨域的實(shí)現(xiàn)步驟,感興趣的可以了解一下
    2023-05-05
  • vue3 中使用 reactive 的問(wèn)題小結(jié)

    vue3 中使用 reactive 的問(wèn)題小結(jié)

    在 Vue 3 中,如果你使用 reactive 來(lái)定義一個(gè)響應(yīng)式對(duì)象,那么這個(gè)對(duì)象的屬性是不能被重新賦值的,因?yàn)?nbsp;reactive 會(huì)將對(duì)象的屬性轉(zhuǎn)換為 getter/setter,這樣 Vue 才能追蹤到屬性的變化,這篇文章主要介紹了vue3 中使用 reactive 的問(wèn)題,需要的朋友可以參考下
    2024-03-03

最新評(píng)論

苏尼特左旗| 神池县| 安丘市| 河曲县| 招远市| 连州市| 镇康县| 泸西县| 云南省| 越西县| 巫溪县| 曲麻莱县| 赤城县| 江阴市| 廊坊市| 察哈| 乐都县| 阜康市| 兴安县| 宁明县| 大冶市| 晋城| 宾川县| 孟津县| 宿迁市| 柯坪县| 江门市| 阿荣旗| 澄城县| 郯城县| 永仁县| 双牌县| 奎屯市| 启东市| 云龙县| 稷山县| 炎陵县| 子长县| 神池县| 海宁市| 河源市|