GithubHelp home page GithubHelp logo

gluncle / vue-menu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from daniel-cintra/vue-menu

0.0 0.0 0.0 2.67 MB

A simple example of implementing a slide menu using Vue.js 2 and Vue Router 3.

JavaScript 16.34% CSS 24.90% HTML 6.81% Vue 51.95%

vue-menu's Introduction

An example of slide menu using Vue and Vue Router

This is a simplified version of the responsive menu I implemented in the Admin Panel of a project some time ago. It uses Vue.js and Vue Router and shares some ideas of how to start puting the framework, router, styles and other concepts together.

vue menu demo

Customizing

The menu can be easily customized for your needs changing:

  1. src/components/Menu.vue where the root level itens can be found.

  2. src/components/support/menu-data.js where the childs of root level itens can be found.

  3. src/router.js where each route can be mapped to load the correspondent component. For the sake of simplicity, with exception of the home route, the sections are loaded dynamically in this example.

Customizing: src/components/Menu.vue

You can find the root level itens of the menu here. In this example, the four root itens (Home, Products, Customers, Account) are coded directly in the Menu component, but could be set as data properties or loaded from external resources.

Example of one root level iten definition:

    <template>

    ...
    <li>
        <a
        href="#"
        @click.prevent="updateMenu('products')"
        :class="highlightSection('products')"
        >
          <i class="fa fa-tag menu__icon" aria-hidden="true"></i>
          Products
          <i class="fa fa-chevron-right menu__arrow-icon" aria-hidden="true"></i>
        </a>
    </li>
    ...

    </template>

Customizing: src/components/support/menu-data.js

You can set the childs of the root itens here.

export default {

  // home is a section without childs, set as an empty array
  home: [],

  products: [

    {
      type: 'title',
      txt: 'Products',
      icon: 'fa fa-tag context-menu__title-icon',
    },

    {
      type: 'link',
      txt: 'List Products',
      link: '/page',
    },

    {
      type: 'link',
      txt: 'Add New Product',
      link: '/page',
    },

    {
      type: 'link',
      txt: 'Manage Categories',
      link: '/page',
    },

  ],
  ...

}

Customizing: src/router.js

Add routes and components mappings here.

import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'

Vue.use(Router)

export default new Router({
  mode: 'history',

  routes: [

    // loads Home component
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/page/:sectionSlug',
      name: 'dynamicContent',
      // route level code-splitting
      // this generates a separate chunk (dynamicContent.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "dynamicContent" */ './views/DynamicContent.vue')
    },

  ]
})

Styles

The styles use Sass css extension language and BEM Methodology. Each component has the correspondent .scss file in src/styles, and is imported in src/App.vue. This way, is easy to see how the final css is composed, and the order of the included files (note the media queries in the end of the .scss imports).

@import 'styles/layout.scss';
@import 'styles/menu-toggle-btn.scss';
@import 'styles/menu.scss';
@import 'styles/content-overlay.scss';
@import 'styles/media-queries.scss';

Demo

There's an online demo here.

Project setup

yarn install

Compiles and hot-reloads for development

yarn run serve

Compiles and minifies for production

yarn run build

Lints and fixes files

yarn run lint

License

This menu is licensed under the Mit License.

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.