vue-vtree

Universal tree component for Vue.js
2,964 7
Install
npm install vue-vtree
Latest Version:0.1.2
License:MIT
Last Updated:Apr 22, 2019
Links: GitHub  ·  npm
Maintainer: xahtep26

vue-vtree

Universal and flexible tree component for Vue.js

Installation

NPM

npm install vue-vtree

CDN

jsDelivr
<script src="https://cdn.jsdelivr.net/npm/vue-vtree@latest/dist/v-tree.min.js"></script>
unpkg
<script src="https://unpkg.com/vue-vtree"></script>

Getting Started

In your script entry point:

import Vue from 'vue';
import VTree from 'vue-vtree';
Vue.component('v-tree', VTree);

Usage

Just write one level of tree in scoped-slot and pass children data to empty child v-tree component and it will inherit the parent slot template.

<template>
  <div id="app">
    <v-tree :scope-data="menu">
      <ul slot-scope="menuLevel">
        <li v-for="menuItem in menuLevel">
          <a :href="https://github.com/XAHTEP26/vue-vtree/blob/HEAD/menuItem.url">{{ menuItem.title }}</a>
          <v-tree v-if="menuItem.children" :scope-data="menuItem.children"></v-tree>
        </li>
      </ul>
    </v-tree>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        menu: [
          { title: 'Home', url: '#' },
          {
            title: 'Posts',
            url: '#',
            children: [
              { title: 'Development', url: '#' },
              { title: 'Design', url: '#' },
              { title: 'Other', url: '#' }
            ]
          },
          {
            title: 'Handbooks',
            url: '#',
            children: [
              {
                title: 'HTML',
                url: '#',
                children: [
                  { title: 'a', url: '#' },
                  { title: 'span', url: '#' },
                  { title: 'div', url: '#' }
                ]
              },
              {
                title: 'CSS',
                url: '#',
                children: [
                  { title: 'display', url: '#' },
                  { title: 'position', url: '#' },
                  { title: 'background', url: '#' },
                  { title: 'border', url: '#' }
                ]
              },
            ]
          },
        ]
      }
    }
  }
</script>

Live Demo

Property "scope-data" can take any value.

Demo for JSON

Demo for Number

License

The MIT License

Related Packages

vue-jstree

a tree plugin for vue2

137,015 630
vue-tree-list-new

A vue component for tree structure. Support adding treenode/leafnode, editing no...

902 1
hu-tree

tree

636
vue-json-tree

Vue component that renders JSON data in a collapsible tree structure.

141,887 50
json-tree-view-vue3

JSON tree rendering Vue3 component

110,063 39

Version History

Version Released License
0.1.2 MIT
0.1.1 MIT
0.1.0 MIT