vue 树形插件_vue2的树形插件

本文介绍了vue2的树形插件vue-jstree,包括NPM安装、ES6导入、设置及用法。还详细讲解了API、节点模型的方法和触发的事件,如@item-click和@item-toggle。此外,还提到了数据项的可选属性。

vue 树形插件

vue-jstree (vue-jstree)

A tree plugin for vue2.

vue2的树形插件。

vue-jstree

NPM (NPM)

npm install vue-jstree

ES6 (ES6)

import VJstree from 'vue-jstree'
    
    new Vue({
      components: {
        VJstree
      }
    })

建立 (Setup)

npm install
    npm run dev

用法 (Usage)

<v-jstree :data="data" show-checkbox multiple allow-batch whole-row @item-click="itemClick"></v-jstree>
    
    new Vue({
      data: {
        data: [
          {
            "text": "Same but with checkboxes",
            "children": [
              {
                "text": "initially selected",
                "selected": true
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-danger"
              },
              {
                "text": "initially open",
                "icon": "fa fa-folder icon-state-default",
                "opened": true,
                "children": [
                  {
                    "text": "Another node"
                  }
                ]
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-warning"
              },
              {
                "text": "disabled node",
                "icon": "fa fa-check icon-state-success",
                "disabled": true
              }
            ]
          },
          {
            "text": "Same but with checkboxes",
            "opened": true,
            "children": [
              {
                "text": "initially selected",
                "selected": true
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-danger"
              },
              {
                "text": "initially open",
                "icon": "fa fa-folder icon-state-default",
                "opened": true,
                "children": [
                  {
                    "text": "Another node"
                  }
                ]
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-warning"
              },
              {
                "text": "disabled node",
                "icon": "fa fa-check icon-state-success",
                "disabled": true
              }
            ]
          },
          {
            "text": "And wholerow selection"
          }
        ]
      },
      methods: {
        itemClick (node) {
          console.log(node.model.text + ' clicked !')
        }
      }
    })

API (API)

PropsTypeDefault
dataArray
sizeString
showCheckboxBooleanfalse
wholeRowBooleanfalse
noDotsBooleanfalse
multipleBooleanfalse
allowBatchBooleanfalse
textFieldNameBoolean'text'
valueFieldNameBoolean'value'
asyncFunction
loadingTextString'Loading'
draggableBooleanfalse
klassString
道具 类型 默认
数据 数组
尺寸
showCheckbox 布尔型
整行 布尔型
无点 布尔型
布尔型
allowBatch 布尔型
textFieldName 布尔型 '文本'
valueFieldName 布尔型 '值'
异步的 功能
loadingText “加载中”
可拖动的 布尔型
克拉斯

node.model中的方法 (Methods in node.model)

MethodParams
addChild(object) newDataItem
addAfter(object) newDataItem, (object) selectedNode
addBefore(object) newDataItem, (object) selectedNode
openChildren
closeChildren
方法 参数
addChild (对象)newDataItem
addAfter (对象)newDataItem,(对象)selectedNode
addBefore (对象)newDataItem,(对象)selectedNode
openChildren
closeChildren

事件 (Event)

@item-click

@ item-click

@item-toggle

@ item-toggle

数据项可选属性 (Data Item Optional Properties)

NameTypeDefault
iconString
openedBooleanfalse
selectedBooleanfalse
disabledBooleanfalse
名称 类型 默认
图标
开了 布尔型
已选 布尔型
残障人士 布尔型

翻译自: https://vuejsexamples.com/a-tree-plugin-for-vue2/

vue 树形插件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值