Git Product home page Git Product logo

vue3-router-tree's Introduction

Vue 3 router tree

This component is based on Vue.js 3, it represents your routes or items as a tree view, by default takes it takes the routes configuration as items, but you could provide your custom items that respects the following format :

[
  {
      path:'/somePath',//optional
      name:'someName',//required
      component:SomeComponent //optional but if it's provided the tree node will be a link that redirects to this component
      children:[


      ]
  }

]

You could also add any other field that you need it when you want to customize the items rendering

Demo

LIVE DEMO or you could check this boilerplate on codesandbox

Installation

 npm install vue3-router-tree --save

Usage

With router :

<vue3-router-tree />

with custom items :

<template>
	<div class="demo">
		<vue3-router-tree :items="routes"> </vue3-router-tree>
	</div>
</template>

<script lang="ts">
	import { defineComponent } from 'vue';

	import Vue3RouterTree from 'vue3-router-tree';
	export default defineComponent({
		data() {
			return {
				routes: [
					{
						path: '/',
						name: 'Home',
						hasIcon: true,
					},
					{
						path: '/dashboard',
						name: 'Dashboard',
						hasIcon: true,
					},
					{
						path: '/component',
						name: 'Components',
						hasIcon: true,
						children: [
							{
								path: '/alerts',
								name: 'Alerts',
							},
							{
								path: '/avatars',
								name: 'Avatars',
							},
							{
								path: '/buttons',
								name: 'Buttons',
							},
							{
								path: '/forms',
								name: 'Forms',
								children: [
									{
										path: '/autocompletes',
										name: 'Autocompletes',
									},
									{
										path: '/checkboxes',
										name: 'Checkboxes',
									},
								],
							},
						],
					},
				],
			};
		},
	});
</script>

props :

Name default description
items [] the tree items or if not provided the component renders the current available routes
active-color "#5d1df1" the color of the active sub node
default-open '' specify the default opened path
exclude-field '' In your route config you could specify a field inside meta option which will be used to exclude
open-all '' Expand all items that have children

slots :

Name description
item override the default item rendering

vue3-router-tree's People

Contributors

boussadjra avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

vue3-router-tree's Issues

OnClick function for the tree

Is there a way I can add an onclick function on the tree items?
I am looking to utilize this as a File tree for in browser editing, and I want to be able to select the file in the list, and have it run a function that will open the file in the text editor.

How would I define the function ran on selecting an item?

Error: Can't resolve '.vue3-router-tree'

Hello thanks for your great project, but im new to vuejs and i cant make it work on my project.

I have installed your project and import it, but it says not found
this what my code look like
<template><vue3-router-tree :items="routes"> </vue3-router-tree></template>
`<script>
import Vue3RouterTree from '.vue3-router-tree';
export default {
name: 'categoryProduct',
components: {
Vue3RouterTree
// Loading
},
data: function(){
return {
routes: [
{
path: '/',
name: 'Home',
hasIcon: true,
},
{
path: '/dashboard',
name: 'Dashboard',
hasIcon: true,
},
{
path: '/component',
name: 'Components',
hasIcon: true,
children: [
{
path: '/alerts',
name: 'Alerts',
},
{
path: '/avatars',
name: 'Avatars',
},
{
path: '/buttons',
name: 'Buttons',
},
{
path: '/forms',
name: 'Forms',
children: [
{
path: '/autocompletes',
name: 'Autocompletes',
},
{
path: '/checkboxes',
name: 'Checkboxes',
},
],
},
],
},
],
}
},
}

<script>` and when i remove the dot in import `import Vue3RouterTree from 'vue3-router-tree';` it shows error TypeError: Object(...) is not a function Please help me solve this, thank you

No Tree is Rendered

I have a warning in my console and not sure if it is the cause of there being no tree rendered:

[Vue warn]: inject() can only be used inside setup() or functional components.

The warning relates to line 54 in index.tsx?d1dd:54 which if I follow the link to the source is the following line in your package:

const router = useRouter()

As far as I can tell my routes object is as required and I see the items in the VueJs Dev tools when inspecting the component.

Any ideas?

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.