elementUI 动态生成几行几列的方法示例

2020-06-13 10:26:31易采站长站整理

elementUI 动态生成几行几列 table

现在碰到一个需求:就是根据用户选择的行列,来自动生成相应大小的 table,如下这个实现还不完善,因为数据不对,只是实现了动态的效果,仅是提供一种实现思路吧,后续我会再想想看怎么实现为好,先记录一下吧
直接看代码吧


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>elementUI table 动态生成列</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<style type="text/css">
@import url("https://unpkg.com/element-ui/lib/theme-chalk/index.css");
</style>
</head>
<body>

<div id="app">

<el-form inline>

<!--先选择 排数-->
<el-form-item label="请选择排" style="margin-left: 50px;">
<el-select style="width: 100% ;" v-model="row1" placeholder="请选择排" @change="row1Change">
<el-option v-for="item in floorNumList" :key="item.floorId"
:value="item.floorId"></el-option>
</el-select>
</el-form-item>

<!--再选择 列数-->
<el-form-item label="请选择列">
<el-select style="width: 100% ;" v-model="col1" placeholder="请选择列" @change="col1Change">
<el-option v-for="item in floorNumList" :key="item.floorId"
:value="item.floorId"></el-option>
</el-select>
</el-form-item>

<el-table ref="multipleTable" :data="rowDataList1" style="width:80%; border: 2px solid red; max-height: 500px; margin-left: 30px;" highlight-current-row :cell-style="cellStyle">
<el-table-column fixed type="selection" align="center" width="50" label="列"></el-table-column>
<!-- <el-table-column type="index" align="center" width="50" label="索引"></el-table-column>-->
<el-table-column v-for="col in colDataList1" :prop="col.id" :label="col.id" align="center" >
<el-table-column prop="id" align="center" >
<template slot-scope="scope">
<el-button @click="handleClick(scope.row, col.id, scope.$index)" class="el-icon-cherry" v-bind:style="{ color: activeColor}">></el-button>
</template>
</el-table-column>
</el-table-column>
</el-table>
</el-form>
</div>
</div>

<script>
let vm = new Vue({
el: '#app',
data(){
return{
floorNumList: [
{floorId: 1},
{floorId: 2},
{floorId: 3},
{floorId: 4},
{floorId: 5},
{floorId: 6},
{floorId: 7},
{floorId: 8},
{floorId: 9},