您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關使用vue怎么編寫一根根樹狀表格,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
1. 初始化配置
安裝模塊:
npm i vue-table-with-tree-grid -S
main.js 文件
import ZkTable from 'vue-table-with-tree-grid' Vue.component(ZkTable.name, ZkTable);
2. 使用
<template lang="html"> <div id="example"> <zk-table ref="table" index-text="#" :data="data" :columns="columns" :stripe="props.stripe" :border="props.border" :show-header="props.showHeader" :show-summary="props.showSummary" :show-row-hover="props.showRowHover" :show-index="props.showIndex" :tree-type="props.treeType" :is-fold="props.isFold" :expand-type="props.expandType" :selection-type="props.selectionType"> <template slot="likes" scope="scope"> {{ scope.row.likes.join(',') }} </template> </zk-table> </div> </template> <script> export default { name: 'example', data() { return { props: { stripe: false, // 是否顯示間隔斑馬紋 border: true, // 是否顯示縱向邊框 showHeader: true, // 是否顯示表頭 showSummary: false, // 是否顯示表尾合計行 showRowHover: true, // 鼠標懸停時,是否高亮當前行 showIndex: true, // 是否顯示數據索引 treeType: true, // 是否為樹形表格 isFold: true, // 樹形表格中父級是否默認折疊 expandType: false, // 是否為展開行類型表格(為 True 時,需要添加名稱為 '$expand' 的作用域插槽, 它可以獲取到 row, rowIndex) selectionType: false, // 是否為多選類型表格 }, data: [ { name: 'Jack', sex: 'male', likes: ['football', 'basketball'], score: 10, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, }, ], }, ], }, ], }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, }, ], }, { name: 'Tom', sex: 'male', likes: ['football', 'basketball'], score: 20, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, }, ], }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, }, ], }, ], }, { name: 'Tom', sex: 'male', likes: ['football', 'basketball'], score: 20, }, { name: 'Tom', sex: 'male', likes: ['football', 'basketball'], score: 20, children: [ { name: 'Ashley', sex: 'female', likes: ['football', 'basketball'], score: 20, }, { name: 'Taki', sex: 'male', likes: ['football', 'basketball'], score: 10, }, ], }, ], columns: [ { label: 'name', // 列標題名稱 prop: 'name', // 對應列內容的屬性名 width: '400px', // 列寬度 }, { label: 'sex', prop: 'sex', minWidth: '50px', }, { label: 'score', prop: 'score', }, { label: 'likes', prop: 'likes', minWidth: '200px', type: 'template', template: 'likes', // 列類型為 'template'(自定義列模板) 時,對應的作用域插槽(它可以獲取到 row, rowIndex, column, columnIndex)名稱 }, ], }; }, }; </script> <style scoped lang="less"> * { margin: 0; padding: 0; } .switch-list { margin: 20px 0; list-style: none; overflow: hidden; } .switch-item { margin: 20px; float: left; } </style>
看完上述內容,你們對使用vue怎么編寫一根根樹狀表格有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。