您的位置:首页 > Web前端 > Vue.js

Vue动态生成表格的行和列

2019-07-18 16:11 1421 查看

当在开发项目的时候,固定的页面表格标题及内容不能满足需求,需要根据不同的需求动态加载不同的表格表头和表格的内容,具体的实现代码如下:

<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: '小学'
}, {
dataItem: 'chuzhong',
dataName: '初中'
}, {
dataItem: 'gaozhong',
dataName: '高中'
}, {
dataItem: 'daxue',
dataName: '大学'
}, {
dataItem: 'yanjiusheng',
dataName: '研究生'
}, {
dataItem: 'shangban',
dataName: '上班'
}]
}
},
methods: {
// 获取表格选中时的数据
selectArInfo (val) {
this.selectArr = val
}
}
}
</script>

实现的效果如下图所示,这个只是一个小的简单示例,表格的数据都是写死的,在我们的项目开发的过程中,我们需要根据自己的开发需求去调用相应的接口,实现相应的表格内容。

以上就是本文的全部内容,希望对大家的学习有所帮助

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vue 表格