欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

將之前的用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為一個(gè)數(shù)組,在data中給treeData一個(gè)初始值:

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

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

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

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

總結(jié)

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

相關(guān)文章

  • vue3實(shí)戰(zhàn)-子組件之間相互傳值問題

    vue3實(shí)戰(zhàn)-子組件之間相互傳值問題

    這篇文章主要介紹了vue3實(shí)戰(zhàn)-子組件之間相互傳值問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • 詳解vue 自定義marquee無縫滾動(dòng)組件

    詳解vue 自定義marquee無縫滾動(dòng)組件

    這篇文章主要介紹了vue自定義marquee無縫滾動(dòng)組件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Vue使用watch監(jiān)聽一個(gè)對象中的屬性的實(shí)現(xiàn)方法

    Vue使用watch監(jiān)聽一個(gè)對象中的屬性的實(shí)現(xiàn)方法

    這篇文章主要介紹了Vue使用watch監(jiān)聽一個(gè)對象中的屬性的實(shí)現(xiàn)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-05-05
  • Babel自動(dòng)生成Attribute文檔實(shí)現(xiàn)詳解

    Babel自動(dòng)生成Attribute文檔實(shí)現(xiàn)詳解

    這篇文章主要為大家介紹了Babel自動(dòng)生成Attribute文檔實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • 淺談Vue中的this.$store.state.xx.xx

    淺談Vue中的this.$store.state.xx.xx

    這篇文章主要介紹了Vue中的this.$store.state.xx.xx用法,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • vue3快速實(shí)現(xiàn)主題切換功能的步驟詳解

    vue3快速實(shí)現(xiàn)主題切換功能的步驟詳解

    本文介紹一種基于css變量的主題切換實(shí)現(xiàn)方式,這種是最簡單,最直接,最容易理解的方式,實(shí)現(xiàn)的原理就是定義不同的HTML根標(biāo)簽元素的樣式,通過data屬性來區(qū)分不同主題css變量樣式,感興趣的朋友可以參考下
    2024-06-06
  • VueJS組件之間通過props交互及驗(yàn)證的方式

    VueJS組件之間通過props交互及驗(yàn)證的方式

    本篇文章主要介紹了VueJS組件之間通過props交互及驗(yàn)證的方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-09-09
  • 使用Nuxt.js改造已有項(xiàng)目的方法

    使用Nuxt.js改造已有項(xiàng)目的方法

    這篇文章主要介紹了使用Nuxt.js改造已有項(xiàng)目的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • vue3?element?plus?table?selection展示數(shù)據(jù),默認(rèn)選中功能方式

    vue3?element?plus?table?selection展示數(shù)據(jù),默認(rèn)選中功能方式

    這篇文章主要介紹了vue3?element?plus?table?selection展示數(shù)據(jù),默認(rèn)選中功能方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • 一篇文章學(xué)會(huì)Vue中間件管道

    一篇文章學(xué)會(huì)Vue中間件管道

    這篇文章主要給大家介紹了如何通過一篇文章學(xué)會(huì)Vue中間件管道的相關(guān)資料,什么是中間件管道?中間件管道是一堆不同的中間件并行運(yùn)行,本文通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-06-06

最新評論