Vue.js 2 tree navigation with vue-router support
For more detailed information see documentation/demo
FeaturesNavigationItem--active
, NavigationLevel--level-1
, NavigationLevel--closed
)Let's suppose you use vue-router with the following routes definition
const routes = [
  {
    name: 'Home',
    path: '/',
  },
  {
    name: 'Running',
    path: '/running',
    children: [
      {
        name: 'Barefoot',
        path: 'barefoot',
      },
    ],
  },
  {
    name: 'Yoga',
    path: '/yoga',
    children: [
      {
        name: 'Mats',
        path: 'mats',
      },
      {
        name: 'Tops',
        path: 'tops',
      },
    ],
  },
  {
    name: 'About',
    path: '/about',
    children: [
      {
        name: 'Career',
        path: 'career',
        children: [
          {
            name: 'Design',
            path: 'design',
          },
        ],
      },
    ],
  },
];
Then simply include vue-tree-navigation
<template>
  <vue-tree-navigation />
</template>
and it will generate the following menu:
- Home // --> /
- Running // --> /running
- Barefoot // --> /running/barefoot
- Yoga // --> /yoga
- Mats // --> /yoga/mats
- Tops // --> /yoga/tops
- About // --> /about
- Career // --> /about/career
- Design // --> /about/career/design
Do not forget to use named routes since vue-tree-navigation uses name
field to label navigation items.
The following configuration
<template>
  <vue-tree-navigation :items="items" />
</template>
Â
<script>
  export default {
    data() {
      return {
        items: [
          { name: 'Products', children: [
            { name: 'Shoes', path: 'shoes' }
          ]},
          { name: 'About', path: 'about', children: [
            { name: 'Contact', path: 'contact', children: [
              { name: 'E-mail', element: 'email' },
              { name: 'Phone', element: 'phone' }
            ]},
          ]},
          { name: 'Github', external: 'https://github.com' },
        ],
      };
    },
  };
</script>Â
will generate
- Products // category label
- Shoes // --> /shoes
- About // --> /about
- Contact // --> /about/contact
- E-mail // --> /about/contact#email
- Phone // --> /about/contact#phone
- Github // --> https://github.com
For more examples see documentation/demo
Installation NPM$ npm install vue-tree-navigation
main.js
Include with a script tagimport VueTreeNavigation from 'vue-tree-navigation';
Â
Vue.use(VueTreeNavigation);
<script src="https://unpkg.com/vue-tree-navigation@4.0.0/dist/vue-tree-navigation.js"></script>
Â
<script>
  Vue.use(VueTreeNavigation)
</script>Â
Example
Requirements Developers<div id="app">
  <vue-tree-navigation :items="items" :defaultOpenLevel="1" />
</div>
Â
<script>
  Vue.use(VueTreeNavigation)
Â
  const app = new Vue({
    el: '#app',
    data: {
      items: [
        ...
      ],
    }
  })
</script>Â
$ yarn dev
Â
$ yarn build
Â
$ yarn prettier
$ yarn lint
Â
$ yarn unit
$ yarn unit --verbose
Â
$ yarn e2e
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4