Vue動(dòng)態(tài)生成表格的行和列
當(dāng)在開發(fā)項(xiàng)目的時(shí)候,固定的頁面表格標(biāo)題及內(nèi)容不能滿足需求,需要根據(jù)不同的需求動(dòng)態(tài)加載不同的表格表頭和表格的內(nèi)容,具體的實(shí)現(xiàn)代碼如下:
<template> <div class="boxShadow"> <div style="margin-top: 20px"> <el-table :data="tables" ref="multipleTable" tooltip-effect="dark" style="width: 100%" @selection-change='selectArInfo'> <el-table-column type="selection" width="45px"></el-table-column> <el-table-column label="序號" width="62px" type="index"> </el-table-column> <template v-for='(col) in tableData'> <el-table-column sortable :show-overflow-tooltip="true" :prop="col.dataItem" :label="col.dataName" :key="col.dataItem" width="124px"> </el-table-column> </template> <el-table-column label="操作" width="80" align="center"> <template slot-scope="scope"> <el-button size="mini" class="del-com" @click="delTabColOne()" ><i class="iconfont icon-shanchu"></i></el-button> </template> </el-table-column> </el-table> </div> </div> </template>
<script> import '../../assets/css/commlist.css' import '../../assets/css/commscoped.sass' export default { data () { return { tables: [{ xiaoxue: '福蘭', chuzhong: '加芳', gaozhong: '蒲廟', daxue: '西安', yanjiusheng: '西安', shangban: '北京' }, { xiaoxue: '南坊', chuzhong: '禮泉', gaozhong: '禮泉', daxue: '西安', yanjiusheng: '西安', shangban: '南坊' }, { xiaoxue: '馬山', chuzhong: '加芳', gaozhong: '蒲廟', daxue: '西安', yanjiusheng: '重慶', shangban: '北京' }], tableData: [{ dataItem: 'xiaoxue', dataName: '小學(xué)' }, { dataItem: 'chuzhong', dataName: '初中' }, { dataItem: 'gaozhong', dataName: '高中' }, { dataItem: 'daxue', dataName: '大學(xué)' }, { dataItem: 'yanjiusheng', dataName: '研究生' }, { dataItem: 'shangban', dataName: '上班' }] } }, methods: { // 獲取表格選中時(shí)的數(shù)據(jù) selectArInfo (val) { this.selectArr = val } } } </script>
實(shí)現(xiàn)的效果如下圖所示,這個(gè)只是一個(gè)小的簡單示例,表格的數(shù)據(jù)都是寫死的,在我們的項(xiàng)目開發(fā)的過程中,我們需要根據(jù)自己的開發(fā)需求去調(diào)用相應(yīng)的接口,實(shí)現(xiàn)相應(yīng)的表格內(nèi)容。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
element-ui table行點(diǎn)擊獲取行索引(index)并利用索引更換行順序
這篇文章主要介紹了element-ui table行點(diǎn)擊獲取行索引(index)并利用索引更換行順序,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02Vue3中的shallowRef?和shallowReactive對比分析
這篇文章主要介紹了Vue3中的shallowRef?和shallowReactive,通過示例代碼逐一對他們的使用做的詳細(xì)介紹,文末補(bǔ)充介紹了vue3的shallowRef()、shallowReactive()和shallowReadonly()的使用,需要的朋友可以參考下2023-01-01Vue+ElementUI 中級聯(lián)選擇器Bug問題的解決
這篇文章主要介紹了Vue+ElementUI 中級聯(lián)選擇器Bug問題的解決方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07