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

基于 Vue 的樹(shù)形選擇組件的示例代碼

 更新時(shí)間:2017年08月18日 09:47:40   作者:ZhuFaner  
本篇文章主要介紹了基于 Vue 的樹(shù)形選擇組件的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

本文介紹了基于 Vue 的樹(shù)形選擇組件。分享給大家,具體如下:

系統(tǒng)要求:Vue 2

基本特性

  •  完美的多級(jí)聯(lián)動(dòng)效果
  •  支持無(wú)限多的分級(jí)
  •  有 全選、半選、不選 三種狀態(tài)

 截圖展示

代碼如下:

 <!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <link rel="icon"  rel="external nofollow" type="image/x-icon">
 <title>Vue Tree Select Example</title>
 <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
</head>
<body>

 <!-- 遞歸引用的模板 -->
 <template id="one-select" style="display: none;">
  <ul>
   <li v-for="(node, key, index) in tree">
    <div v-if="key != 'selected'">
     <div v-on:click="nodeClick(node, index)" v-bind:class="[node.selected == null ? 'tree-select-null' : (node.selected == 'half' ? 'tree-select-half' : 'tree-select-full'), 'tree-select', 'inline-block']"></div>
     
     <div class="inline-block">{{ key }}</div>
     <div v-if="key != ''">
      <one-select v-bind:tree="node" v-bind:isroot="false"></one-select>
     </div>
    </div>
   </li>
  </ul>
 </template>

 <!-- 整體樹(shù)容器 -->
 <div id="tree">
  <one-select v-bind:isroot="true" v-bind:tree="tree"></one-select>
 </div>

<textarea id="treeDataJSON" style="display: none;">
{
 "客戶(hù)管理": {
  "我的客戶(hù)": {
   "新分配": {},
   "跟進(jìn)中": {},
   "簽單客戶(hù)": {},
   "長(zhǎng)期客戶(hù)": {}
  },
  "長(zhǎng)期客戶(hù)權(quán)限": {
   "設(shè)為長(zhǎng)期客戶(hù)": {},
   "還原長(zhǎng)期客戶(hù)": {}
  }
 },
 "采購(gòu)列表": {
  "添加異??颓?: {},
  "添加采購(gòu)單": {},
  "采購(gòu)?fù)素泦瘟斜?: {},
  "供應(yīng)商管理": {},
  "供應(yīng)商聯(lián)系人": {},
  "品牌列表": {
   "寶潔": {},
   "樂(lè)視": {
    "樂(lè)視網(wǎng)": {},
    "樂(lè)視手機(jī)": {
     "樂(lè)視手機(jī) 1": {},
     "樂(lè)視手機(jī) 2": {},
     "樂(lè)視手機(jī) 3": {},
     "樂(lè)視手機(jī) 4": {},
     "樂(lè)視手機(jī) 5": {
      "體驗(yàn)超深層級(jí)": {
       "繼續(xù)體驗(yàn)超深層級(jí)": {
        "依然體驗(yàn)超深層級(jí)": {},
        "依然體驗(yàn)超深層級(jí) 2": {}
       }
      }
     }
    },
    "樂(lè)視電視": {}
   },
   "可口可樂(lè)": {},
   "圣象": {}
  }
 }
}
</textarea>

<script>
// 初始數(shù)據(jù)
var treeDataJSON = document.getElementById("treeDataJSON").value;
var treeData = JSON.parse(treeDataJSON);
Vue.component('one-select', {
 name: 'one-select',
 template: '#one-select',
 props: ['tree', 'isroot'],
 created: function() {
  var realTree = Object.assign({}, this.tree);
  delete realTree.selected;
  if (Object.keys(realTree).length === 0) { // 判斷最低級(jí),再刷新父級(jí)
   this.refreshAllParentNodes(this.$parent);
  }
 },
 methods: {
  nodeClick: function(node, index) {
   if (node.selected === 'full' || node.selected === 'half') {
    Vue.set(node, 'selected', null);
   } else {
    Vue.set(node, 'selected', 'full');
   }
   this.refreshAllParentNodes(self.$parent);
   this.refreshAllParentNodes(this);
   this.refreshAllSonNodes(this.$children[index], node.selected);
  },
  refreshAllSonNodes: function(node, status) {
   if (node instanceof Vue && node.$children.length) {
    for (index in node.$children) {
     Vue.set(node.$children[index].tree, 'selected', status);
     // 遞歸計(jì)算子級(jí)
     this.refreshAllSonNodes(node.$children[index], status);
    }
   }
  },
  refreshAllParentNodes: function(node) {
   if (node instanceof Vue) {
    var status = null;
    var nullCount = 0;
    var halfCount = 0;
    var fullCount = 0;
    for (index in node.$children) {
     if (typeof node.$children[index].tree.selected === 'undefined') {
      nullCount++;
     } else if (node.$children[index].tree.selected === null) {
      nullCount++;
     } else if (node.$children[index].tree.selected === 'half') {
      halfCount++;
     } else if (node.$children[index].tree.selected === 'full') {
      fullCount++;
     }
    }
    if (fullCount === node.$children.length) {
     status = 'full';
    } else if (nullCount === node.$children.length) {
     status = null;
    } else {
     status = 'half';
    }
    Vue.set(node.tree, 'selected', status);

    // 遞歸計(jì)算父級(jí)
    this.refreshAllParentNodes(node.$parent);
   }
  },
  log: function(o) {
   console.log(o);
  }
 }
});
vm = new Vue({
 el: '#tree',
 data: {
  tree: treeData
 },
 methods: {
  // 返回最終數(shù)據(jù)
  getResult: function() {
   return Object.assign({}, this.tree);
  }
 }
});
</script>

<style>
#tree {
 width: 500px;
 margin: 0 auto;
 margin-top: 50px;
}
li {
 list-style: none;
 line-height: 25px;
}
.inline-block {
 display: inline-block;
}
.tree-select {
 width: 13px;
 height: 13px;
 line-height: 16px;
 margin: 3px;
 display: inline-block;
 vertical-align: middle;
 border: 0 none;
 cursor: pointer;
 outline: none;
 background-color: transparent;
 background-repeat: no-repeat;
 background-attachment: scroll;
 background-image: url('selects.png');
}
.tree-select-null {
 background-position: 0 0;
}
.tree-select-full {
 background-position: -14px 0;
}
.tree-select-half {
 background-position: -14px -28px;
}
</style>

</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue項(xiàng)目?jī)?yōu)化打包詳解

    Vue項(xiàng)目?jī)?yōu)化打包詳解

    這篇文章主要為大家介紹了Vue項(xiàng)目的優(yōu)化打包,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • vue計(jì)算屬性computed的使用方法示例

    vue計(jì)算屬性computed的使用方法示例

    這篇文章主要介紹了vue計(jì)算屬性computed的使用方法,結(jié)合實(shí)例形式分析了vue計(jì)算屬性computed的基本用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2019-03-03
  • vue axios請(qǐng)求攔截實(shí)例代碼

    vue axios請(qǐng)求攔截實(shí)例代碼

    axios 是一個(gè)基于Promise 用于瀏覽器和 nodejs 的 HTTP 客戶(hù)端.這篇文章主要介紹了vue/axios請(qǐng)求攔截的相關(guān)知識(shí),需要的朋友可以參考下
    2018-03-03
  • vue使用jsonp抓取qq音樂(lè)數(shù)據(jù)的方法

    vue使用jsonp抓取qq音樂(lè)數(shù)據(jù)的方法

    這篇文章主要介紹了vue使用jsonp抓取qq音樂(lè)數(shù)據(jù)的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-06-06
  • element帶輸入建議el-autocomplete的使用

    element帶輸入建議el-autocomplete的使用

    本文主要介紹了element帶輸入建議el-autocomplete的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • vue實(shí)現(xiàn)輸入一位數(shù)字轉(zhuǎn)漢字功能

    vue實(shí)現(xiàn)輸入一位數(shù)字轉(zhuǎn)漢字功能

    這篇文章主要介紹了vue實(shí)現(xiàn)輸入一位數(shù)字轉(zhuǎn)漢字功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • 使用vue進(jìn)行Lodop打印的一些常用方法小結(jié)

    使用vue進(jìn)行Lodop打印的一些常用方法小結(jié)

    這篇文章主要給大家介紹了關(guān)于使用vue進(jìn)行Lodop打印的一些常用方法,需要進(jìn)行打印功能,Lodop就是實(shí)現(xiàn)需求的插件,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • vue自定義全局組件(自定義插件)的用法

    vue自定義全局組件(自定義插件)的用法

    這篇文章主要介紹了vue自定義全局組件(自定義插件)的用法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • vue使用pinia實(shí)現(xiàn)全局無(wú)縫通信

    vue使用pinia實(shí)現(xiàn)全局無(wú)縫通信

    這篇文章主要為大家詳細(xì)介紹了vue如何使用pinia實(shí)現(xiàn)全局無(wú)縫通信,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下
    2023-11-11
  • Vue?2中實(shí)現(xiàn)CustomRef方式防抖節(jié)流

    Vue?2中實(shí)現(xiàn)CustomRef方式防抖節(jié)流

    這篇文章主要為大家介紹了Vue?2中實(shí)現(xiàn)CustomRef方式防抖節(jié)流示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02

最新評(píng)論

揭阳市| 台南县| 开江县| 类乌齐县| 南丹县| 锡林浩特市| 桐梓县| 朝阳县| 白城市| 固安县| 北宁市| 襄汾县| 弋阳县| 五寨县| 乡宁县| 连云港市| 岳池县| 顺平县| 罗甸县| 乳山市| 突泉县| 兰溪市| 汉沽区| 仙桃市| 巴彦淖尔市| 汾阳市| 洪洞县| 昆山市| 利津县| 北辰区| 余庆县| 清镇市| 佛教| 宁波市| 晋城| 龙游县| 响水县| 沙河市| 苍梧县| 始兴县| 金溪县|