1
1
<template >
2
2
<div class =" container" >
3
- <Nav v-if =" isShowNav" />
3
+ <Nav v-if =" state. isShowNav" />
4
4
<div class =" layout" >
5
5
<router-view />
6
- <CustomSlider v-if =" isShowSlider" ></CustomSlider >
6
+ <CustomSlider v-if =" state. isShowSlider" ></CustomSlider >
7
7
</div >
8
8
<ArrowUp ></ArrowUp >
9
9
<!-- <Footer v-if="isShowNav"></Footer> -->
10
10
</div >
11
11
</template >
12
12
13
13
<script lang="ts">
14
- import { defineComponent , defineAsyncComponent } from " vue" ;
14
+ import { defineComponent , defineAsyncComponent , reactive , onMounted } from " vue" ;
15
+ import { useRouter , useRoute , onBeforeRouteUpdate } from ' vue-router' ;
15
16
import { isMobileOrPc } from " ./utils/utils" ;
16
17
17
18
// 移动端 rem 单位适配
@@ -26,80 +27,68 @@ if (isMobileOrPc()) {
26
27
export default defineComponent ({
27
28
name: " App" ,
28
29
components: {
29
- Nav: defineAsyncComponent (() =>
30
- import (' ./components/Nav.vue' )
30
+ Nav: defineAsyncComponent (() => import (" ./components/Nav.vue" )),
31
+ CustomSlider: defineAsyncComponent (
32
+ () => import (" ./components/CustomSlider.vue" )
31
33
),
32
- CustomSlider: defineAsyncComponent (() =>
33
- import (' ./components/CustomSlider.vue' )
34
- ),
35
- Footer: defineAsyncComponent (() =>
36
- import (' ./components/Footer.vue' )
37
- ),
38
- ArrowUp: defineAsyncComponent (() =>
39
- import (' ./components/Footer.vue' )
40
- ),
41
- },
42
- data() {
43
- return {
44
- isShowNav: false ,
45
- isShowSlider: false ,
46
- };
34
+ Footer: defineAsyncComponent (() => import (" ./components/Footer.vue" )),
35
+ ArrowUp: defineAsyncComponent (() => import (" ./components/Footer.vue" )),
47
36
},
48
37
watch: {
49
38
$route : function (val : any , oldVal : any ) {
50
39
this .routeChange (val , oldVal );
51
- // const referrer: any = document.getElementById("referrer");
52
- // if (val.path === "/") {
53
- // this.isShowNav = false;
54
- // referrer.setAttribute("content", "always");
55
- // } else {
56
- // this.isShowNav = true;
57
- // referrer.setAttribute("content", "never");
58
- // }
59
- // if (
60
- // val.path === "/articles" ||
61
- // val.path === "/archive" ||
62
- // val.path === "/project" ||
63
- // val.path === "/timeline" ||
64
- // val.path === "/message"
65
- // ) {
66
- // this.isShowSlider = true;
67
- // } else {
68
- // this.isShowSlider = false;
69
- // }
70
- // if (isMobileOrPc()) {
71
- // this.isShowSlider = false;
72
- // }
73
40
},
74
41
},
75
- methods: {
76
- routeChange(val : any , oldVal : any ): void {
42
+ setup() {
43
+ const state = reactive ({
44
+ isShowNav: false ,
45
+ isShowSlider: false ,
46
+ });
47
+
48
+ // const router = useRouter();
49
+ const route = useRoute ();
50
+
51
+ const routeChange = (val : any , oldVal : any ): void => {
77
52
const referrer: any = document .getElementById (" referrer" );
78
53
if (val .path === " /" ) {
79
- this .isShowNav = false ;
54
+ state .isShowNav = false ;
80
55
referrer .setAttribute (" content" , " always" );
81
56
} else {
82
- this .isShowNav = true ;
57
+ state .isShowNav = true ;
83
58
referrer .setAttribute (" content" , " never" );
84
59
}
85
- if (
86
- val .path === " /articles" ||
87
- val .path === " /archive" ||
88
- val .path === " /project" ||
89
- val .path === " /timeline" ||
90
- val .path === " /message"
91
- ) {
92
- this .isShowSlider = true ;
60
+ const navs = [
61
+ " /articles" ,
62
+ " /archive" ,
63
+ " /archive" ,
64
+ " /project" ,
65
+ " /timeline" ,
66
+ " /message" ,
67
+ ];
68
+ if (navs .includes (val .path )) {
69
+ state .isShowSlider = true ;
93
70
} else {
94
- this .isShowSlider = false ;
71
+ state .isShowSlider = false ;
95
72
}
96
73
if (isMobileOrPc ()) {
97
- this .isShowSlider = false ;
74
+ state .isShowSlider = false ;
98
75
}
99
- },
100
- },
101
- mounted(): void {
102
- this .routeChange (this .$route , this .$route );
76
+ };
77
+
78
+ onMounted (() => {
79
+ routeChange (route , route );
80
+ })
81
+
82
+ // onBeforeRouteUpdate((to: any, from: any) => {
83
+ // console.log(to, "=====");
84
+ // console.log(from, "=====");
85
+ // routeChange(to, from);
86
+ // });
87
+
88
+ return {
89
+ state ,
90
+ routeChange ,
91
+ };
103
92
},
104
93
});
105
94
</script >
@@ -109,14 +98,13 @@ export default defineComponent({
109
98
@import url(" ./less/index.less" );
110
99
@import url(" ./less/mobile.less" );
111
100
#app {
112
- font-family : Avenir,Helvetica ,Arial ,sans-serif ;
113
- -webkit-font-smoothing : antialiased ;
114
- -moz-osx-font-smoothing : grayscale ;
115
- text-align : left ;
116
- color : #2c3e50 ;
117
- width : 1200px ;
118
- margin : 0 auto ;
119
- padding-top : 61px ;
101
+ font-family : Avenir, Helvetica , Arial , sans-serif ;
102
+ -webkit-font-smoothing : antialiased ;
103
+ -moz-osx-font-smoothing : grayscale ;
104
+ text-align : left ;
105
+ color : #2c3e50 ;
106
+ // width: 1200px;
107
+ padding-top : 61px ;
120
108
}
121
109
img {
122
110
vertical-align : bottom ;
0 commit comments