Skip to content

Commit

Permalink
feat(routes): basic menu items in store
Browse files Browse the repository at this point in the history
  • Loading branch information
smartapant committed Feb 18, 2017
1 parent 7dd9633 commit 1b367ef
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = {
'vue$': 'vue/dist/vue.common.js',
'src': resolve('src'),
'assets': resolve('src/assets'),
'components': resolve('src/components')
'components': resolve('src/components'),
'vuex-store': resolve('src/store')
}
},
module: {
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import store from './store'
import router from './router'
import { sync } from 'vuex-router-sync'
import store from './store'

sync(store, router)

Expand Down
2 changes: 2 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Charts from 'components/statistics/charts/Charts'
import ProgressBars from 'components/statistics/progress-bars/ProgressBars'
import Dashboard from 'components/dashboard/Dashboard'

// import menuModule from 'vuex-store/modules/menu'

Vue.use(Router)

export default new Router({
Expand Down
5 changes: 5 additions & 0 deletions src/store/getters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const menuitems = state => state.menu.items

export {
menuitems
}
6 changes: 5 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import Vue from 'vue'
import Vuex from 'vuex'

import menu from './modules/menu'
import * as getters from './getters'

Vue.use(Vuex)

const store = new Vuex.Store({
strict: true, // process.env.NODE_ENV !== 'production',
getters,
modules: {

menu
},
state: {
},
Expand Down
38 changes: 38 additions & 0 deletions src/store/modules/menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as types from '../../mutation-types'
import lazyLoading from './lazyLoading'
import statistics from './statistics'

// show: meta.label -> name
// name: component name
// meta.label: display label

const state = {
items: [
{
name: 'Dashboard',
path: '/dashboard',
meta: {
icon: 'fa-tachometer'
},
component: lazyLoading('dashboard/Dashboard')
},
statistics
]
}

const mutations = {
[types.EXPAND_MENU] (state, menuItem) {
if (menuItem.index > -1) {
if (state.items[menuItem.index] && state.items[menuItem.index].meta) {
state.items[menuItem.index].meta.expanded = menuItem.expanded
}
} else if (menuItem.item && 'expanded' in menuItem.item.meta) {
menuItem.item.meta.expanded = menuItem.expanded
}
}
}

export default {
state,
mutations
}
3 changes: 3 additions & 0 deletions src/store/modules/menu/lazyLoading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// lazy loading Components
// https://github.com/vuejs/vue-router/blob/dev/examples/lazy-loading/app.js#L8
export default (name, index = false) => () => import(`components/${name}${index ? '/index' : ''}.vue`)
23 changes: 23 additions & 0 deletions src/store/modules/menu/statistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import lazyLoading from './lazyLoading'

export default {
name: 'Statistics',
path: '/statistics',
meta: {
expanded: false
},
component: lazyLoading('charts', true),

children: [
{
name: 'Charts',
path: 'charts',
component: lazyLoading('statistics/charts/Charts')
},
{
name: 'ProgressBars',
path: 'progress-bars',
component: lazyLoading('statistics/progress-bars/ProgressBars')
}
]
}
1 change: 1 addition & 0 deletions src/store/mutation-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const EXPAND_MENU = 'EXPAND_MENU'

0 comments on commit 1b367ef

Please sign in to comment.