最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue組件橫向樹實(shí)現(xiàn)代碼

 更新時間:2018年08月02日 10:32:56   作者:若晨工作室  
這篇文章主要介紹了vue組件橫向樹實(shí)現(xiàn)代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

將之前的用css3+jq實(shí)現(xiàn)的橫向樹樣式簡單封裝成組件使用到vue項(xiàng)目中,文件名為transverseTree.vue

代碼:

<template>
 <div class="tree">
  <ul v-if="treeData && treeData.length">
   <li v-for="(column,index) in treeData">
    <span class="root">{{column.name}}</span>
    <ul v-if="column.children && column.children.length">
     <li v-for="(childrenColumn,index) in column.children">
      <span>{{childrenColumn.name}}</span>
      <ul v-if="childrenColumn.children && childrenColumn.children.length">
       <li v-for="(grandChildrenColumn,index) in childrenColumn.children">
        <span>{{grandChildrenColumn.name}}</span>
       </li>
      </ul>
     </li>
    </ul>
   </li>
  </ul>
 </div>
</template>
<script>
 export default {
 name: 'transverseTree',
 props: {
  treeData:{
   type:Array,
   default:[]
  }
 },
 methods: {
  editDom(){
   if($('.root').siblings('ul').children('li').length==1){
    let num = 26*($('.root').siblings('ul').children('li').find('li').length-1);
    $('.root').css({ 'top': num });
    $('.root').siblings('ul').children('li').css({ 'top': num });
    $('.root').siblings('ul').find('ul').css({ 'top': -num });
    if($('.root').siblings('ul').find('li').length > 1){
     $('.root').siblings('ul').children('li').children('span').addClass('hasChild');
    }
   }else{
    $('.root').css({ 'top': 26 * ($('.root').siblings('ul').children('li').length - 1) });
   }
  }
 },
 mounted() {
  this.$nextTick(()=>{
   this.editDom();
  });
 }
 };
</script>
<style scope>
.tree{
 position: relative;
 margin: -16px -16px 0;
 min-height: 400px;
 padding-left: 11px;
 overflow: auto;
}
.tree ul{
 width: 210px;
 height: 100%;
 position: absolute;
}
.tree ul ul{
 left: 226px;
 top: 0;
}
.tree li{
 float: left;
 list-style-type: none;
 position: relative;
 padding: 16px 5px 0 5px;
}
.tree li span{
 position: relative;
 display: inline-block;
 width: 200px;
 height: 36px;
 background: #F0F0F5;
 border-radius: 4px;
 text-decoration: none;
 color: #2D2D2D;
 font-size: 14px;
 line-height: 36px;
 text-align: center;
}
.tree li::before{
 box-sizing:inherit;
 content: '';
 position: absolute;
 top: 33px;
 left: -7px;
 border-top: 2px solid #D2D2D7;
 width: 12px;
}
.tree li::after{
 box-sizing:inherit;
 content: '';
 position: absolute;
 top: 8px;
 left: -9px;
 height: 100%;
 border-left: 2px solid #D2D2D7;
}
.tree li:first-child::after{
 height: 51%;
 border-left: 2px solid #D2D2D7;
 border-top: 2px solid #D2D2D7;
 top: 33px;
 width: 1px;
 border-top-left-radius: 4px;
}
.tree li:last-child::after{
 height: 25px;
 border-left: 2px solid #D2D2D7;
 border-bottom: 2px solid #D2D2D7;
 top: 8px;
 width: 1px;
 border-bottom-left-radius: 4px;
}
.tree li:only-child::after,
.tree li:only-child::before{
 display: none;
}
.tree ul ul li:only-child::before{
 display: inline-block;
}
.tree ul ul li:only-child span::before{
 display: inline-block;
}
.tree li:only-child span.root::before,.tree li:only-child span.hasChild::before{
 content: '';
 position: absolute;
 top: 17px;
 right: -14px;
 border-top: 2px solid #D2D2D7;
 width: 14px;
}
.tree ul ul ul li:only-child span::before{
 content: '';
 position: absolute;
 top: 17px;
 left: -26px;
 border-top: 2px solid #D2D2D7;
 width: 26px;
}
</style>

在父組件中使用import引入該組件:

import transverseTree from './transverseTree'

注冊組件:

components: { ifbpInfolistCard,transverseTree },

在template中使用:

<transverse-tree :treeData='treeData'></transverse-tree>

其中,treeData為一個數(shù)組,在data中給treeData一個初始值:

treeData: [
{name:'報表名稱1',
children:[
{name:'功能名稱1',
children:[
{name:'磁貼名稱1'}
]},
{name:'功能名稱2',
children:[
{name:'磁貼名稱1'}
]},
{name:'功能名稱3',
children:[
{name:'磁貼名稱1'}
]},
]}
]

實(shí)現(xiàn)效果:

ps:需要特別說明的是,我目前的代碼暫時只支持這兩種樣式,即:

1父節(jié)點(diǎn)-1子節(jié)點(diǎn)-1/多孫節(jié)點(diǎn),或是1父節(jié)點(diǎn)-多子節(jié)點(diǎn)-1孫節(jié)點(diǎn),樣式是通過jq去判斷修改的,以后有時間的話再去研究優(yōu)化爭取可復(fù)用性強(qiáng)一些。希望對大家能有所幫助。

總結(jié)

以上所述是小編給大家介紹的vue組件橫向樹實(shí)現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

青河县| 开鲁县| 江安县| 昆山市| 常宁市| 磐石市| 南川市| 临武县| 威宁| 榆林市| 贡觉县| 大竹县| 都昌县| 商城县| 化德县| 白银市| 共和县| 永福县| 安顺市| 金沙县| 西华县| 泽州县| 阜新| 祁东县| 喀什市| 枣庄市| 酉阳| 新郑市| 浦城县| 日喀则市| 惠州市| 上饶县| 阿勒泰市| 文山县| 临邑县| 黄骅市| 蓬溪县| 紫阳县| 霍州市| 封丘县| 蒙山县|