亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

vue中Element-ui表格如何實現樹形結構表格

發布時間:2022-05-06 13:51:49 來源:億速云 閱讀:1919 作者:iii 欄目:大數據

這篇文章主要介紹“vue中Element-ui表格如何實現樹形結構表格”,在日常操作中,相信很多人在vue中Element-ui表格如何實現樹形結構表格問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”vue中Element-ui表格如何實現樹形結構表格”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

前端效果展示:

vue中Element-ui表格如何實現樹形結構表格

在el-table中,支持樹類型的數據的顯示。當 row 中包含 children 字段時,被視為樹形數據。渲染樹形數據時,必須要指定 row-key。支持子節點數據異步加載。

通過指定 row 中的 hasChildren 字段來指定哪些行是包含子節點。children 與 hasChildren 都可以通過 tree-props 配置。

row-key="id"和:tree-props="{children: 'children', hasChildren: 'hasChildren'}是必須的。

下面是vue的表格樹:

 <!--表格-->  
       <el-row>
            <el-table :data="tableData"  row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                        <el-table-column prop="privilegeName" label="權限名稱" >
                        </el-table-column>
                        <el-table-column prop="privilegeCode" label="權限編碼" >
                        </el-table-column>
                        <el-table-column prop="privilegeType" label="權限類別" :formatter="formatPrivilegeType" >
                        </el-table-column>
 
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                
                                <el-button type="primary" size="mini" @click="toAdd(scope)">新增</el-button>
                                <el-button type="primary" size="mini" @click="toEdit(scope)">編輯</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <br>
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.pageIndex"
                        :page-sizes="[5, 10, 20, 30, 40]"
                        :page-size=pagination.pageSize
                        layout="total, prev, pager, next"
                        :total=pagination.total>
                    </el-pagination>
</el-row>

后端代碼:SpringBoot+MyPlus+MySQL8 實現數據結構查詢

前端全部代碼:

<style>
</style>
<template>
  <div id="privilege-manager">
   <!--頂部菜單欄-->
    <el-form :inline="true" class="demo-form-inline">
          <el-form-item>
            <el-button
              class="el-icon-refresh"
              type="primary"
              @click="toAdd()">添加
            </el-button>
          </el-form-item>
      </el-form>
      <!--表格-->  
       <el-row>
            <el-table :data="tableData"  row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                        <el-table-column prop="privilegeName" label="權限名稱" >
                        </el-table-column>
                        <el-table-column prop="privilegeCode" label="權限編碼" >
                        </el-table-column>
                        <el-table-column prop="privilegeType" label="權限類別" :formatter="formatPrivilegeType" >
                        </el-table-column>
 
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                
                                <el-button type="primary" size="mini" @click="toAdd(scope)">新增</el-button>
                                <el-button type="primary" size="mini" @click="toEdit(scope)">編輯</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <br>
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.pageIndex"
                        :page-sizes="[5, 10, 20, 30, 40]"
                        :page-size=pagination.pageSize
                        layout="total, prev, pager, next"
                        :total=pagination.total>
                    </el-pagination>
        </el-row>
 
 
  </div>
</template>
 
<script>
export default{
    name: 'privilege-manager',
    data () {
     return {
        tableData: [],
        dialogFormEdit: false,
        dialogFormAdd:false,
        privilege: {
          id: '',
          privilegeName: '',
          privilegeCode: '',
          privilegeType: '',
          pid: '0'
        },
        pagination: {
            pageIndex: 1,
            pageSize: 10,
            total: 0,
        }
      }
    },
    methods:{
         init () {
        var self = this
         this.$axios({
            method:'post',
            url:'/api/baoan/privilege/getPage',
            data:{"page":this.pagination.pageIndex,"limit":this.pagination.pageSize, "pid": this.privilege.pid},
            headers:{
                'Content-Type':'application/json;charset=utf-8'      //改這里就好了
          }
        }).then(res => {
           console.log(res);
           self.pagination.total = res.data.datas.data.total;
           self.tableData = res.data.datas.data.records;
        })
          .catch(function (error) {
            console.log(error)
          })
        },
        handleSizeChange(val) {
                console.log(`每頁 ${val} 條`);
                this.pagination.pageSize = val;
                this.pagination.pageIndex = 1;
                this.init();
        },
        handleCurrentChange(val) {
                 console.log(`當前頁: ${val}`);
                this.pagination.pageIndex = val;
                this.init();
        },
        // 權限類別轉換
        formatPrivilegeType: function( row, column) {
                 if(row.privilegeType === '1'){
                     return '目錄'
                 } else if(row.privilegeType === '2') {
                     return '菜單'
                 } else if (row.privilegeType === '3') {
                     return '按鈕'
                 } else {
                     return ''
                 }
        }
    },
    mounted: function () {
      this.init()
  }
 
 
}
</script>

到此,關于“vue中Element-ui表格如何實現樹形結構表格”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

咸丰县| 宁国市| 琼结县| 温泉县| 宜丰县| 新民市| 云林县| 高台县| 郯城县| 大兴区| 舞阳县| 澳门| 五华县| 桦甸市| 和田县| 金溪县| 拉萨市| 瓦房店市| 南岸区| 西乌珠穆沁旗| 英吉沙县| 磐安县| 日照市| 太白县| 宜兰市| 墨玉县| 达日县| 玛曲县| 红河县| 博白县| 洞头县| 苏尼特右旗| 宜春市| 准格尔旗| 抚顺县| 奎屯市| 开远市| 民权县| 通河县| 大新县| 宁晋县|