Skip to content

Commit 1c141ff

Browse files
committed
layout1,通过vuex读取左侧菜单
1 parent 3b4df35 commit 1c141ff

File tree

7 files changed

+177
-3
lines changed

7 files changed

+177
-3
lines changed

.babelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"targets": {
44
"browsers": ["last 2 versions"]
55
}
6-
}]]
6+
}]],
7+
"plugins": [
8+
["transform-object-rest-spread"]
9+
]
710
}

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
'object-curly-spacing': [2, 'always'],
2222
'no-undef': [1],
2323
'new-cap': 1,
24-
'no-param-reassign': 2,
24+
'no-param-reassign': 0,
2525
'global-require': 0,
2626
'no-mixed-operators': 0,
2727
"import/no-extraneous-dependencies": 0,

src/components/layout1.vue

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<template>
2+
<div class="layout">
3+
<el-container style="min-height: 100vh">
4+
<el-header>
5+
<div width="200px" class="logo"></div>
6+
</el-header>
7+
<el-container>
8+
<el-aside width="200px">
9+
<el-row class="tac">
10+
<el-col :span="24">
11+
<template v-if="menu.length">
12+
<el-menu
13+
:default-active="defaultActive"
14+
class="el-menu-vertical-demo"
15+
@open="handleOpen"
16+
@close="handleClose"
17+
background-color="#383a4b"
18+
text-color="#fff"
19+
active-text-color="#ffd04b"
20+
:router="true">
21+
<template v-for="item in menu">
22+
<template v-if="item.sub">
23+
<el-submenu :index="item.key" :key="item.key">
24+
<template slot="title">
25+
<i class="el-icon-location"></i>
26+
<span>{{ item.name }}</span>
27+
</template>
28+
<el-menu-item v-for="subItem in item.sub" :index="subItem.key" :key="subItem.key">
29+
{{ subItem.name }}
30+
</el-menu-item>
31+
</el-submenu>
32+
</template>
33+
<template v-else>
34+
<el-menu-item :index="item.key" :key="item.key">
35+
<i class="el-icon-menu"></i>
36+
<span slot="title">{{ item.name }}</span>
37+
</el-menu-item>
38+
</template>
39+
</template>
40+
</el-menu>
41+
</template>
42+
</el-col>
43+
</el-row>
44+
</el-aside>
45+
<el-container>
46+
<el-main>
47+
<slot name="content"></slot>
48+
</el-main>
49+
<el-footer>July Design ©2017 Created by July</el-footer>
50+
</el-container>
51+
</el-container>
52+
</el-container>
53+
</div>
54+
</template>
55+
56+
<script>
57+
const operateUrl = 'claa/menulist';
58+
59+
export default {
60+
name: 'layout',
61+
data() {
62+
return {
63+
defaultActive: 'item1'
64+
};
65+
},
66+
67+
created() {
68+
this.defaultActive = this.$route.path.split('/')[1] ? this.$route.path.split('/')[1] : 'item1';
69+
},
70+
mounted() {
71+
this.doQuery();
72+
},
73+
74+
computed: {
75+
menu() {
76+
return this.$store.state.menu.menuList;
77+
}
78+
},
79+
methods: {
80+
handleOpen(key, keyPath) {
81+
console.log(key, keyPath);
82+
},
83+
handleClose(key, keyPath) {
84+
console.log(key, keyPath);
85+
},
86+
doQuery() {
87+
const param = {
88+
loadingFlag: true,
89+
url: operateUrl,
90+
method: 'POST',
91+
data: {
92+
type: 'on'
93+
}
94+
};
95+
this.$store.dispatch('fetch', param);
96+
}
97+
}
98+
};
99+
</script>
100+
101+
<style lang="scss" scoped>
102+
.logo{
103+
104+
}
105+
.el-header, .el-footer {
106+
background-color: #383a4b;
107+
color: #fff;
108+
text-align: center;
109+
line-height: 60px;
110+
}
111+
112+
.el-aside {
113+
background-color: #383a4b;
114+
.el-menu{
115+
border-right: 0;
116+
}
117+
}
118+
119+
.el-main {
120+
background-color: #E9EEF3;
121+
}
122+
123+
body > .el-container {
124+
margin-bottom: 40px;
125+
}
126+
127+
</style>

src/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import item2 from 'pages/item2/item2';
99
import item31 from 'pages/item3/option1';
1010
import item32 from 'pages/item3/option2';
1111

12+
import store from './store';
13+
1214
Vue.use(ElementUI);
1315
Vue.use(VueRouter);
1416
/* eslint-disable no-new */
@@ -27,6 +29,7 @@ const router = new VueRouter({
2729
new Vue({
2830
el: '#app',
2931
router,
32+
store,
3033
template: `
3134
<div id="app">
3235
<router-view class="view"></router-view>

src/pages/item1/item1.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</template>
1010

1111
<script>
12-
import Layout from 'components/layout';
12+
import Layout from 'components/layout1';
1313
import Modal from 'components/modal';
1414
1515
export default {

src/store/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Vue from 'vue';
2+
import Vuex from 'vuex';
3+
import menu from './modules/menu';
4+
5+
Vue.use(Vuex);
6+
7+
const store = new Vuex.Store({
8+
modules: {
9+
menu
10+
}
11+
});
12+
13+
export default store;

src/store/modules/menu.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Axios from 'util/axios';
2+
3+
const menu = {
4+
state: {
5+
menuList: []
6+
},
7+
mutations: {
8+
CHANGE_MENULIST: (state, list) => {
9+
state.menuList = list;
10+
}
11+
},
12+
actions: {
13+
fetch({ commit }, param) {
14+
const params = {
15+
...param,
16+
successFn(data) {
17+
if (data.list && data.list.length) {
18+
commit('CHANGE_MENULIST', data.list);
19+
}
20+
}
21+
};
22+
console.log(params);
23+
Axios.fetch(params);
24+
}
25+
}
26+
};
27+
28+
export default menu;

0 commit comments

Comments
 (0)