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實現(xiàn)注冊頁效果?vue實現(xiàn)短信驗證碼登錄
這篇文章主要為大家詳細(xì)介紹了用vue實現(xiàn)注冊頁,短信驗證碼登錄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11
Vue3+Element?Plus實現(xiàn)el-table跨行顯示(非腳手架)
這篇文章主要介紹了Vue3+Element Plus實現(xiàn)el-table跨行顯示(非腳手架),本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-09-09
vue 動態(tài)設(shè)置img的src地址無效,npm run build 后找不到文件的解決
這篇文章主要介紹了vue 動態(tài)設(shè)置img的src地址無效,npm run build 后找不到文件的解決,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
vue實現(xiàn)數(shù)字動態(tài)翻牌的效果(開箱即用)
這篇文章主要介紹了vue實現(xiàn)數(shù)字動態(tài)翻牌的效果(開箱即用),實現(xiàn)原理是激將1到9的數(shù)字豎直排版,通過translate移動位置顯示不同數(shù)字,本文通過實例代碼講解,需要的朋友可以參考下2019-12-12
vue3+element-plus?Dialog對話框的使用與setup?寫法的用法
這篇文章主要介紹了vue3+element-plus?Dialog對話框的使用?與?setup?寫法的使用,本文通過兩種方式結(jié)合實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04

