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

Vue組件模板形式實現(xiàn)對象數(shù)組數(shù)據(jù)循環(huán)為樹形結(jié)構(gòu)(實例代碼)

 更新時間:2017年07月31日 15:49:24   作者:yn_zihuatanejo  
這篇文章主要介紹了Vue組件模板形式實現(xiàn)對象數(shù)組數(shù)據(jù)循環(huán)為樹形結(jié)構(gòu),本文用vue實現(xiàn)方式,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

數(shù)據(jù)結(jié)構(gòu)為數(shù)組中包含對象--樹形結(jié)構(gòu),用Vue組件的寫法實現(xiàn)以下的效果:

樹形列表,縮進(jìn)顯示層級,第5級數(shù)據(jù)加底色,數(shù)據(jù)樣式顯色,點(diǎn)擊展開折疊數(shù)據(jù)。本文為用Vue實現(xiàn)方式,另有一篇為用knockout.js的實現(xiàn)方法。

html代碼

 <div id="table-component-div">
   <table-component v-for="item in data1" v-bind:list="item"></table-component>
 </div>

組件模板代碼

<script type="text/x-template" id="table-component-template">
  <div class="tem">
    <div class="tem-p">
      <div v-on:click="toggleClick"><i v-bind:style="{'visibility':list.number!=0?'visible':'hidden'}">{{list.number}}</i><span>{{list.name}}</span></div>
      <!--綁定數(shù)據(jù)-->
      <div><span>{{list.energyone}}</span></div>
      <div><span>{{list.energytwo}}</span></div>
      <div><span>{{list.energythree}}</span></div>
      <!--綁定class,使數(shù)值顯示出區(qū)分-->
      <div><span v-bind:class="{'isgreen':list.huanRatio<0,'isred':list.huanRatio>100}">{{list.huanRatio}}<em>%</em></span></div>
      <div><span v-bind:class="{'isgreen':list.tongRatio<0,'isred':list.tongRatio>100}">{{list.tongRatio}}<em>%</em></span></div>
    </div>
    <div class="tem-c">
      <!-- 子組件 -->
      <table-component v-for="itemc in list.child" :list="itemc"></table-component>
    </div>
  </div>
</script>

JavaScript代碼

/* 數(shù)據(jù)結(jié)構(gòu) */
    var ko_vue_data=[
      {
        name: "總能耗",
        number:"0",
        energyone: 14410,
        energytwo: 1230,
        energythree: 1230,
        huanRatio: -36.8,
        tongRatio: 148.5,
        child: [
          {
            name: "租戶電耗",
            number:"1",
            energyone: 14410,
            energytwo: 1230,
            energythree: 1230,
            huanRatio: -36.8,
            tongRatio: 148.5,
            child: []
          },
          {
            name: "公共用電",
            number:"2",
            energyone: 14410,
            energytwo: 1230,
            energythree: 1230,
            huanRatio: -36.8,
            tongRatio: 148.5,
            child: [
              {
                name: "暖通空調(diào)",
                number:"2.1",
                energyone: 14410,
                energytwo: 1230,
                energythree: 1230,
                huanRatio: -36.8,
                tongRatio: 148.5,
                child: [
                  {
                    name: "冷站",
                    number:"2.1.1",
                    energyone: 14410,
                    energytwo: 1230,
                    energythree: 1230,
                    huanRatio: -36.8,
                    tongRatio: 148.5,
                    child: [
                      {
                        name: "冷水機(jī)組",
                        number:"2.1.1.1",
                        energyone: 14410,
                        energytwo: 1230,
                        energythree: 1230,
                        huanRatio: -36.8,
                        tongRatio: 148.5,
                        child: []
                      }
                    ]
                  },
                  {
                    name: "熱力站",
                    number: "2.1.2",
                    energyone: 14410,
                    energytwo: 1230,
                    energythree: 1230,
                    huanRatio: -36.8,
                    tongRatio: 148.5,
                    child: []
                  }
                ]
              }
            ]
          }
        ]
      }
    ];
    /* 注冊組件 */
    Vue.component('table-component', {
      template:"#table-component-template",//模板
      props:['list'],//傳遞數(shù)據(jù)
      computed:{//計算屬性
        isFolder: function () {//判斷數(shù)據(jù)有沒有子集,此效果中暫沒用到,有需要的可以看下具體使用方式
          return this.list.child && this.list.child.length > 0;
        }
      },
      methods:{
        /* 展開折疊操作 */
        toggleClick:function(event){
          event.stopPropagation();//阻止冒泡
          var _this = $(event.currentTarget);//點(diǎn)擊的對象
          if (_this.parent().next().is(":visible")) {
            _this.parent().next().slideUp();
          } else {
            _this.parent().next().slideDown();
          }
        }
      }
    });
    /* 創(chuàng)建實例 */
    new Vue({
      el:"#table-component-div",//掛載dom
      data:{
        data1:ko_vue_data//數(shù)據(jù)
      }
    })

數(shù)據(jù)顯示完畢,接下來是樣式效果,縮進(jìn)顯示層級及底色顯示。

css代碼

.tem-p{
      clear: both;
      border-bottom: 1px solid #dddddd;
      height: 30px;
      line-height: 30px;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
    }
    .tem-p>div{
      float: left;
      width:100px;
      box-sizing: border-box;
      -ms-text-overflow: ellipsis;
      text-overflow: ellipsis;
      white-space:nowrap;
      overflow: hidden;
      text-align: center;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      height: 100%;
      border-right: 1px solid #dddddd;
    }
    .tem-p>div:first-of-type{
      width: 298px;
      text-align: left;
    }
    .tem>.tem-c .tem-p>div:first-of-type{
      padding-left: 30px;
    }
    .tem>.tem-c .tem-c .tem-p>div:first-of-type{
      padding-left: 60px;
    }
    .tem>.tem-c .tem-c .tem-c .tem-p>div:first-of-type{
      padding-left: 90px;
    }
    .tem>.tem-c .tem-c .tem-c .tem-c .tem-p>div:first-of-type{
      padding-left: 120px;
    }
    .tem>.tem-c .tem-c .tem-c .tem-c .tem-p{
      background-color: #f8f8f8;
    }
    .tem>.tem-c .tem-c .tem-c .tem-c .tem-c .tem-p>div:first-of-type{
      padding-left: 150px;
    }
    .lastChild{
      background: #f8f8f8;
    }
    .isred{
      color: red;
    }
    .isgreen{
      color: green;
    }

總結(jié)

以上所述是小編給大家介紹的Vue組件模板形式實現(xiàn)對象數(shù)組數(shù)據(jù)循環(huán)為樹形結(jié)構(gòu),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Vue中的 DOM與Diff詳情

    Vue中的 DOM與Diff詳情

    這篇文章主要介紹了Vue中的 DOM與Diff詳情,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,感興趣的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助
    2022-08-08
  • Vue Ref全家桶具體用法詳解

    Vue Ref全家桶具體用法詳解

    ref用來輔助我們獲取DOM元素或組件的引用實例對象,每個vue的組件實例上,都包含一個refs對象,里面存儲著對應(yīng)的DOM元素或組件的引用,默認(rèn)情況下,組件的refs指向一個空對象
    2023-03-03
  • vuex-persist 使用場景分析

    vuex-persist 使用場景分析

    Vuex-Persist 是一個用于在 Vuex 中實現(xiàn)持久化狀態(tài)的庫,它可以用來解決應(yīng)用程序在刷新瀏覽器或關(guān)閉頁面后丟失 Vuex store 中狀態(tài)的問題,本文給大家介紹vuex-persist 可以用來干什么,感興趣的朋友一起看看吧
    2023-11-11
  • 解決uniapp項目在微信開發(fā)工具里打開報錯Error:app.json:在項目根目錄未找到app.json

    解決uniapp項目在微信開發(fā)工具里打開報錯Error:app.json:在項目根目錄未找到app.json

    這篇文章主要給大家介紹了關(guān)于解決uniapp項目在微信開發(fā)工具里打開報錯Error:app.json:在項目根目錄未找到app.json的相關(guān)資料,文中通過圖文將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下
    2024-03-03
  • vue 組件數(shù)據(jù)加載解析順序的詳細(xì)代碼

    vue 組件數(shù)據(jù)加載解析順序的詳細(xì)代碼

    Vue.js的解析順序可以概括為:模板編譯、組件創(chuàng)建、數(shù)據(jù)渲染、事件處理和生命周期鉤子函數(shù)執(zhí)行,接下來通過本文給大家介紹vue 組件數(shù)據(jù)加載解析順序的完整代碼,感興趣的朋友跟隨小編一起看看吧
    2024-03-03
  • vue全局使用axios的方法實例詳解

    vue全局使用axios的方法實例詳解

    這篇文章主要介紹了vue全局使用axios的方法實例詳解,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-11-11
  • Vue實現(xiàn)簡單的跑馬燈

    Vue實現(xiàn)簡單的跑馬燈

    這篇文章主要為大家詳細(xì)介紹了Vue實現(xiàn)簡單的跑馬燈,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • 在Vue中實現(xiàn)文件預(yù)覽與打印的代碼示例

    在Vue中實現(xiàn)文件預(yù)覽與打印的代碼示例

    在Vue應(yīng)用中,有時我們需要實現(xiàn)文件預(yù)覽和打印的功能,比如,我們可能需要預(yù)覽并打印PDF文件、圖片文件等,本文將介紹如何在Vue中實現(xiàn)文件預(yù)覽和打印的功能,并提供相應(yīng)的代碼示例
    2023-06-06
  • Vue之TodoList案例詳解

    Vue之TodoList案例詳解

    這篇文章主要為大家介紹了Vue之TodoList的案例,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助<BR>
    2021-11-11
  • 關(guān)于element-ui resetFields重置方法無效問題及解決

    關(guān)于element-ui resetFields重置方法無效問題及解決

    這篇文章主要介紹了關(guān)于element-ui resetFields重置方法無效問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08

最新評論

陈巴尔虎旗| 绥中县| 万盛区| 河源市| 沂水县| 义乌市| 尼玛县| 平舆县| 襄垣县| 盈江县| 禹州市| 普陀区| 龙山县| 石嘴山市| 阜平县| 泸溪县| 米泉市| 郓城县| 格尔木市| 玉田县| 龙游县| 年辖:市辖区| 叙永县| 红原县| 云龙县| 神池县| 滦平县| 宝坻区| 新安县| 星子县| 南通市| 报价| 外汇| 宁武县| 图片| 吴旗县| 双鸭山市| 黄浦区| 吉隆县| 津市市| 宁武县|