国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

elementUI 動態生成幾行幾列的方法示例

2024-05-06 15:37:02
字體:
來源:轉載
供稿:網友

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},     {floorId: 10}    ],    floorNum: '',    // 第1層 默認選擇的排數 和 列數    row1: 1,    col1: 1,    // 第2層 默認選擇的排數 和 列數    row2: 1,    col2: 1,    // 第3層 默認選擇的排數 和 列數    row3: 1,    col3: 1,    // 第4層 默認選擇的排數 和 列數    row4: 1,    col4: 1,    // 第5層 默認選擇的排數 和 列數    row5: 1,    col5: 1,    activeColor: 'green',    colPos: '',    rowPos: '',    rowDataList1: [{ // 默認給一個對象,即默認狀態是 1行數據     id: Math.ceil(Math.random()*100)    }],    colDataList1: [     {id: '1'}    ],   }  },  methods:{   col1Change(){    // 每觸發一次,清空數據    this.colDataList1 = [{id: '1'}];    // 取得 選中的第一層的第一排的數值    let len = this.col1;    if(len > 1){     for (let i = 2; i <= len; i++){      this.colDataList1.push({id: i + ''});     }     return this.colDataList1;    }else{     return this.colDataList1;    }   },   row1Change(){    // 每觸發一次,清空數據    this.rowDataList1 = [{ id: Math.ceil(Math.random()*100)}];    let len = this.row1;    if (len > 1){     for (let i = 2; i <= len ; i++){      this.rowDataList1.push({id: Math.ceil(Math.random()*100) + i});     }     return this.rowDataList1;    }else {     return this.rowDataList1;    }   },   handleClick(row, col, index) {    // console.log(JSON.stringify(row));    // console.log(JSON.stringify(col));    // console.log("點擊的cell 行數: " + JSON.stringify(index)); // index 是 行數,0 表示第一行,從 0 開始    // 一點擊獲取 行縱坐標    this.colPos = col;    this.rowPos = index;   },   cellStyle({row, column, rowIndex, columnIndex}){    // console.log(JSON.stringify(row))    // console.log(JSON.stringify(column))    // console.log("要渲染的行數: " + JSON.stringify(rowIndex))    // console.log(JSON.stringify(columnIndex))    if(rowIndex == 0 && columnIndex == 0){     return '';    }else {     if(rowIndex == this.rowPos && columnIndex == this.colPos){ //指定坐標      return 'background: pink';     }else{      return '';     }    }   },  } });</script></body></html>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 康定县| 奇台县| 西吉县| 大田县| 赤峰市| 涿州市| 曲水县| 宁津县| 五台县| 喀喇沁旗| 武冈市| 镇巴县| 元江| 宁陕县| 任丘市| 丹棱县| 浦县| 延寿县| 巨鹿县| 昌宁县| 象州县| 怀化市| 泗阳县| 海口市| 垦利县| 凤山市| 龙岩市| 溆浦县| 宜君县| 和政县| 永兴县| 福安市| 余姚市| 广昌县| 石首市| 台州市| 六盘水市| 杨浦区| 攀枝花市| 电白县| 永州市|