Commit 1306151233bf7cd7598d5e508329f05cd143972a
1 parent
e19eac3d
设置动态document.title
Showing
8 changed files
with
64 additions
and
13 deletions
webintroduce/src/App.vue
1 | 1 | <template> |
2 | 2 | <div id="app"> |
3 | - <VHeader></VHeader> | |
3 | + <VHeader v-if="headerShow"></VHeader> | |
4 | 4 | <div class="main-wrap"> |
5 | 5 | <router-view/> |
6 | 6 | </div> |
7 | 7 | |
8 | - <VFooter></VFooter> | |
8 | + <VFooter v-if="footerShow"></VFooter> | |
9 | 9 | </div> |
10 | 10 | </template> |
11 | 11 | |
... | ... | @@ -17,6 +17,22 @@ export default { |
17 | 17 | components:{ |
18 | 18 | VHeader, |
19 | 19 | VFooter |
20 | + }, | |
21 | + data() { | |
22 | + return { | |
23 | + footerShow: true, | |
24 | + headerShow: true | |
25 | + } | |
26 | + }, | |
27 | + watch: { | |
28 | + $route(to, from){ | |
29 | + console.log(this.$route.path) | |
30 | + if(this.$route.path === '/login'){ | |
31 | + this.headerShow = this.footerShow = false | |
32 | + }else { | |
33 | + this.headerShow = this.footerShow = true | |
34 | + } | |
35 | + } | |
20 | 36 | } |
21 | 37 | } |
22 | 38 | </script> | ... | ... |
webintroduce/src/components/VHeader.vue
... | ... | @@ -5,7 +5,6 @@ |
5 | 5 | :to="{path:link.linkPath}" |
6 | 6 | tag="li" v-for="(link,index) in navLinks" |
7 | 7 | :key="index" |
8 | - @click="navChange(index)" | |
9 | 8 | exact=""> |
10 | 9 | {{link.name}} |
11 | 10 | </router-link> |
... | ... | @@ -20,15 +19,14 @@ export default { |
20 | 19 | return { |
21 | 20 | navLinks: [ |
22 | 21 | {name:'首页',linkPath:'/home'}, |
23 | - {name:'解决方案',linkPath:'/solution'} | |
22 | + {name:'解决方案',linkPath:'/solution'}, | |
23 | + {name:'登录',linkPath:'/login'} | |
24 | 24 | ] |
25 | 25 | } |
26 | 26 | }, |
27 | 27 | methods:{ |
28 | - navChange(index) { | |
28 | + }, | |
29 | 29 | |
30 | - } | |
31 | - } | |
32 | 30 | } |
33 | 31 | </script> |
34 | 32 | ... | ... |
webintroduce/src/main.js
... | ... | @@ -7,6 +7,12 @@ import router from './router' |
7 | 7 | require ('./assets/css/reset.css') |
8 | 8 | Vue.config.productionTip = false |
9 | 9 | |
10 | +router.beforeEach((to, from, next) =>{ | |
11 | + console.log(to) | |
12 | + document.title = to.meta.title | |
13 | + next() | |
14 | +}) | |
15 | + | |
10 | 16 | /* eslint-disable no-new */ |
11 | 17 | new Vue({ |
12 | 18 | el: '#app', | ... | ... |
webintroduce/src/router/index.js
1 | 1 | import Vue from 'vue' |
2 | 2 | import Router from 'vue-router' |
3 | -import VHome from '../views/VHome' | |
4 | -const VSolution = () => import('../views/VSolution') | |
5 | -const VEnterprise = () => import('../views/VEnterprise') | |
3 | +import home from '../views/home' | |
4 | +const solution = () => import('../views/solution') | |
5 | +const enterprise = () => import('../views/enterprise') | |
6 | +const login = () => import('../views/login') | |
6 | 7 | |
7 | 8 | Vue.use(Router) |
8 | 9 | |
... | ... | @@ -16,17 +17,34 @@ export default new Router({ |
16 | 17 | { |
17 | 18 | path: '/home', |
18 | 19 | name: 'home', |
19 | - component: VHome | |
20 | + component: home, | |
21 | + meta: { | |
22 | + title: '首页' | |
23 | + } | |
20 | 24 | }, |
21 | 25 | { |
22 | 26 | path: '/solution', |
23 | 27 | name: 'solution', |
24 | - component: VSolution | |
28 | + component: solution, | |
29 | + meta: { | |
30 | + title: '解决方案' | |
31 | + } | |
25 | 32 | }, |
26 | 33 | { |
27 | 34 | path: '/enterprise/:id', |
28 | 35 | name: 'enterprise', |
29 | - component: VEnterprise | |
36 | + component: enterprise, | |
37 | + meta: { | |
38 | + title: '企业' | |
39 | + } | |
40 | + }, | |
41 | + { | |
42 | + path: '/login', | |
43 | + name: 'login', | |
44 | + component: login, | |
45 | + meta: { | |
46 | + title: '登录' | |
47 | + } | |
30 | 48 | } |
31 | 49 | ] |
32 | 50 | }) | ... | ... |
webintroduce/src/views/VEnterprise.vue renamed to webintroduce/src/views/enterprise.vue
webintroduce/src/views/VHome.vue renamed to webintroduce/src/views/home.vue
webintroduce/src/views/login.vue
0 → 100644
webintroduce/src/views/VSolution.vue renamed to webintroduce/src/views/solution.vue