Giter VIP home page Giter VIP logo

vue-tree's Introduction

v-tree

Usage

1.npm install 下载依赖项 2.npm install vue-tree-jf --save 下载vue-tree-jf组件

import vueTree from 'vue-tree-jf'

Vue.use(vueTree);


.....
<vue-tree  :treeData='datas' ref='vtree' @clickNode ='clickNode' ></vue-tree>

初始化参数

参数 类型 默认值 描述
treeData Array 数据源,包含'id','text','icon','children'属性。
示例:[ {text:'xiaoming', id:'1', icon:'folder', children:[ {text:'1-1', id:'1-1', icon:'folder', children:[ {text:'1-1-1', id:'1-1-1', icon:'file', },{text:'1-1-2', id:'1-1-2', icon:'file' }] },{ text:'1-2', id:'1-2', icon:'folder', }] } ]
checkBox Boolean false 是否显示checkbox
transitionTime Number 200 折叠动画时间,单位ms
expand Boolean true 初始化时折节点展开状态

treeData参数

参数名称 类型 默认值 描述
text String 节点名称
id String 节点id
icon String 节点图标
children Array 节点的子节点

方法

方法名称 参数 返回值 描述
getSelectedNode - 返回选中的tree节点
getCheckedNodes - 返回多选的tree节点 在多选属性checkbox为true时有效。
getRoot - 获取树根节点。
findNode nodeId 节点id 获根据id获取选中节点数据。
setSelectedNode node,ifClick node:节点数据,包含id字段即可。 ifClick:是否触发点击事件 设置树节点选中。
getParentNode node node:节点对象(包含id属性即可) 获取父节点数据。
getParentNodesArr node node:节点对象(包含id属性即可) 获取所有祖先节点数据数组。

事件说明

事件名称 参数 参数说明 描述
clickNode node 当前点击节点的数据 节点点击时触发

Image text

使用示例

<template><div class="hello">
  <vue-tree :treeData='datas' ref='vtree' @clickNode='clickNode' :checkBox='checkbox'></vue-tree>
  <button @click='findSelected'>getNode</button></div>
</template>
<script>
  import Vue from 'vue'
  import vueTree from 'vue-tree-jf'
  Vue.use(vueTree);
  export default {
  name: 'HelloWorld',
  methods:{
      findSelected(){
          console.log('you clicked' + JSON.stringify(this.$refs.vtree.getSelectedNode()));
          if(this.checkbox){
               console.log('you choosed ' + JSON.stringify(this.$refs.vtree.getCheckedNodes()))
          }
      },
      clickNode(target){
        console.log('you clicked '+ target.id)
      }
  },
  data () {
    return {
      msg: 'Welcome to Your vtree App',
      checkbox:true,
      datas:[
        {text:'xiaoming',
          id:'1',
          icon:'folder',
          children:[
              {text:'1-1',
                id:'1-1',
                icon:'folder',
                children:[
                  {text:'1-1-1',
                    id:'1-1-1',
                    icon:'file',

                  },{text:'1-1-2',
                    id:'1-1-2',
                    icon:'file'

                  }]
              
              },{
                text:'1-2',
                id:'1-2',
                icon:'file',
              }]
        },
        {text:'hua',
          id:'2',
          icon:'folder',
          children:[{
            text:'2-2',
            id:'2-2',
            icon:'file',
          }]
        },
        {text:'hua',
          id:'3',
          icon:'folder',
          children:[{
            text:'3-3',
            id:'3-3',
            icon:'file',
          }]
        }
        ]
    }
  },
}
</script>
<style scoped>
.hello{
    float:left;
    width:400px;
    border:1px solid black;
}
</style>

vue-tree's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vue-tree's Issues

Could not resolve "./components/v-tree"

(this will be run only when your dependencies or config have changed)

node_modules/vue-tree-jf/src/index.js:1:20: error: Could not resolve "./components/v-tree"
1 │ import vueTree from './components/v-tree'
╵ ~~~~~~~~~~~~~~~~~~~~~

error when starting dev server:
Error: Build failed with 1 error:
node_modules/vue-tree-jf/src/index.js:1:20: error: Could not resolve "./components/v-tree"
at failureErrorWithLog (D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:1449:15)
at D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:1131:28
at runOnEndCallbacks (D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:921:63)
at buildResponseToResult (D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:1129:7)
at D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:1236:14
at D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:609:9
at handleIncomingPacket (D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:706:9)
at Socket.readFromStdout (D:\go\prometheus_config_manager\admin3\node_modules\esbuild\lib\main.js:576:7)
at Socket.emit (events.js:376:20)
at addChunk (internal/streams/readable.js:309:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @0.0.0 dev: vite
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! D:\nodeJs\node_cache_logs\2021-06-24T04_02_53_894Z-debug.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.