vue實現(xiàn)樹形表格
更新時間:2021年09月18日 09:05:00 作者:Yasmine_ss
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)樹形表格,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)樹形表格的具體代碼,,供大家參考,具體內(nèi)容如下
效果如下:
居中的圖片:
代碼如下:
<template> <div class="treeTable"> <table> <tr> <th>設(shè)備類型</th> <th>產(chǎn)品名稱</th> <th>版本</th> <th>檢查項</th> <th>檢查子項</th> <th>檢查大類</th> <th>設(shè)備小類</th> <th>備注</th> </tr> <tbody> <tr v-for="(item,index) in datas" :key="index" v-show="item.display"> <td :style="{paddingLeft:item.left}"><span @click="nodeClick(index)" v-if="item.branch" :class="item.expand? 'expand':'collapse'"></span>{{item.type}}</td> <td>{{item.name}}</td> <td>{{item.version}}</td> <td>{{item.checkItem}}</td> <td>{{item.checkSubItem}}</td> <td v-if="item.branch">{{item.BigItem}}</td> <td v-else><input type="text" v-model="item.BigItem"></td> <td v-if="item.branch">{{item.smallItem}}</td> <td v-else><input type="text" v-model="item.smallItem"></td> <td v-if="item.branch">{{item.remark}}</td> <td v-else><input type="text" v-model="item.remark"></td> </tr> </tbody> </table> </div> </template> <script> /* eslint-disable */ export default { name: 'treeTable', data () { return { msg: 'Welcome to Your Vue.js App', datas:[ {left:'0',branch:true,expand:true,display:true,id:'1',pid:'0',type:'防火墻',name:'',version:'',checkItem:'',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'0.5rem',branch:true,expand:true,display:true,id:'1_1',pid:'1',type:'防火墻',name:'CE001',version:'',checkItem:'',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'1rem',branch:true,expand:true,display:true,id:'1_1_1',pid:'1_1',type:'防火墻',name:'CE001',version:'VR001',checkItem:'',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'1.5rem',branch:true,expand:true,display:true,id:'1_1_1_1',pid:'1_1_1',type:'防火墻',name:'CE001',version:'VR001',checkItem:'檢查項A',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'3rem',branch:false,expand:true,display:true,id:'1_1_1_1_1',pid:'1_1_1_1',type:'防火墻',name:'CE001',version:'VR001',checkItem:'檢查項A',checkSubItem:'檢查子項A',BigItem:'軟件版本',smallItem:'檢查項A',remark:'備注信息'}, {left:'0',branch:true,expand:true,display:true,id:'2',pid:'0',type:'數(shù)據(jù)交換中心',name:'',version:'',checkItem:'',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'0.5rem',branch:true,expand:true,display:true,id:'2_1',pid:'2',type:'數(shù)據(jù)交換中心',name:'CE001',version:'',checkItem:'',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'1rem',branch:true,expand:true,display:true,id:'2_1_1',pid:'2_1',type:'數(shù)據(jù)交換中心',name:'CE001',version:'VR001',checkItem:'',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'1.5rem',branch:true,expand:true,display:true,id:'2_1_1_1',pid:'2_1_1',type:'數(shù)據(jù)交換中心',name:'CE001',version:'VR001',checkItem:'檢查項A',checkSubItem:'',BigItem:'',smallItem:'',remark:''}, {left:'3rem',branch:false,expand:true,display:true,id:'2_1_1_1_1',pid:'2_1_1_1',type:'數(shù)據(jù)交換中心',name:'CE001',version:'VR001',checkItem:'檢查項A',checkSubItem:'檢查子項A',BigItem:'軟件版本',smallItem:'檢查項A',remark:'備注信息'}, ], } }, methods:{ nodeClick(index){ this.datas[index].expand = this.datas[index].expand ? false : true let pid = this.datas[index].id if(this.datas[index].expand){ for(let i = index +1;i<this.datas.length;i++){ let reg = new RegExp('^'+pid) if(this.datas[i].pid == pid){ this.datas[i].display = true this.datas[i].expand = false }else if(reg.test(this.datas[i].id)){ this.datas[i].display = false this.datas[i].expand = false }else{ break } } }else{ for(let i = index +1;i<this.datas.length;i++){ let reg = new RegExp('^'+pid) if(reg.test(this.datas[i].id)){ this.datas[i].display = false this.datas[i].expand = false }else{ break } } } // for(let i = index +1;i<this.datas.length;i++){ // let reg = new RegExp('^'+pid) // if(reg.test(this.datas[i].id)){ // if(this.datas[index].expand){ // this.datas[i].display = true // }else{ // this.datas[i].display = false // this.datas[i].expand = false // } // } // } } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> th,td{ width: 150px; } td:first-child{ text-align: left; } td span{ display: inline-block; width: 1.5rem; height: 1rem; } td span.expand{ background-image: url('./folder_open.png'); } td span.collapse{ background-image: url('./folder.png'); } </style>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue-router重寫push方法,解決相同路徑跳轉(zhuǎn)報錯問題
這篇文章主要介紹了vue-router重寫push方法,解決相同路徑跳轉(zhuǎn)報錯問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08Vue實現(xiàn)按鈕旋轉(zhuǎn)和移動位置的實例代碼
這篇文章主要介紹了Vue實現(xiàn)按鈕旋轉(zhuǎn)和移動位置的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-08-08Vue3+echarts5踩坑以及resize方法報錯的解決
這篇文章主要介紹了Vue3+echarts5踩坑以及resize方法報錯的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07基于Vue2實現(xiàn)移動端圖片上傳、壓縮、拖拽排序、拖拽刪除功能
這篇文章主要介紹了基于Vue2實現(xiàn)移動端圖片上傳、壓縮、拖拽排序、拖拽刪除功能,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01Vuex管理dialog、toast等常見全局性組件狀態(tài)時唯一性的問題解決
工作中經(jīng)常會用到類似于?dialog、toast、popover?等一些狀態(tài)提示組件,這篇文章主要介紹了Vuex管理dialog、toast等常見全局性組件狀態(tài)時唯一性的問題,需要的朋友可以參考下2022-11-11Vue-drag-resize 拖拽縮放插件的使用(簡單示例)
本文通過代碼給大家介紹了Vue-drag-resize 拖拽縮放插件使用簡單示例,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12