Skip to content

Commit 9cc2db1

Browse files
Merge pull request #21 from biaochenxuying/dev
Dev
2 parents b753f0b + 95b20fc commit 9cc2db1

19 files changed

+1759
-1850
lines changed

src/App.vue

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<template>
22
<div class="container">
3-
<Nav v-if="isShowNav" />
3+
<Nav v-if="state.isShowNav" />
44
<div class="layout">
55
<router-view />
6-
<CustomSlider v-if="isShowSlider"></CustomSlider>
6+
<CustomSlider v-if="state.isShowSlider"></CustomSlider>
77
</div>
88
<ArrowUp></ArrowUp>
99
<!-- <Footer v-if="isShowNav"></Footer> -->
1010
</div>
1111
</template>
1212

1313
<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';
1516
import { isMobileOrPc } from "./utils/utils";
1617
1718
// 移动端 rem 单位适配
@@ -26,80 +27,68 @@ if (isMobileOrPc()) {
2627
export default defineComponent({
2728
name: "App",
2829
components: {
29-
Nav: defineAsyncComponent(() =>
30-
import('./components/Nav.vue')
30+
Nav: defineAsyncComponent(() => import("./components/Nav.vue")),
31+
CustomSlider: defineAsyncComponent(
32+
() => import("./components/CustomSlider.vue")
3133
),
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")),
4736
},
4837
watch: {
4938
$route: function (val: any, oldVal: any) {
5039
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-
// }
7340
},
7441
},
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 => {
7752
const referrer: any = document.getElementById("referrer");
7853
if (val.path === "/") {
79-
this.isShowNav = false;
54+
state.isShowNav = false;
8055
referrer.setAttribute("content", "always");
8156
} else {
82-
this.isShowNav = true;
57+
state.isShowNav = true;
8358
referrer.setAttribute("content", "never");
8459
}
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;
9370
} else {
94-
this.isShowSlider = false;
71+
state.isShowSlider = false;
9572
}
9673
if (isMobileOrPc()) {
97-
this.isShowSlider = false;
74+
state.isShowSlider = false;
9875
}
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+
};
10392
},
10493
});
10594
</script>
@@ -109,14 +98,13 @@ export default defineComponent({
10998
@import url("./less/index.less");
11099
@import url("./less/mobile.less");
111100
#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;
120108
}
121109
img {
122110
vertical-align: bottom;

src/components/About.vue

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/components/ArrowUp.vue

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,39 @@
99
</div>
1010
</template>
1111
<script lang="ts">
12-
import { defineComponent } from "vue";
12+
import { defineComponent, reactive, onMounted } from "vue";
1313
1414
export default defineComponent({
1515
name: "ArrowUp",
16-
data() {
17-
return {
16+
setup() {
17+
const state = reactive({
1818
isShowBtn: false,
19-
};
20-
},
21-
mounted() {
22-
// 当网页向下滑动 20px 出现"返回顶部" 按钮
23-
window.onscroll = (): void => {
24-
if (
25-
window.document.body.scrollTop > 100 ||
26-
window.document.documentElement.scrollTop > 100
27-
) {
28-
this.isShowBtn = true;
29-
} else {
30-
this.isShowBtn = false;
31-
}
32-
};
33-
},
34-
methods: {
35-
topFunction(): void {
19+
});
20+
21+
onMounted(() => {
22+
// 当网页向下滑动 20px 出现"返回顶部" 按钮
23+
window.onscroll = (): void => {
24+
if (
25+
window.document.body.scrollTop > 100 ||
26+
window.document.documentElement.scrollTop > 100
27+
) {
28+
state.isShowBtn = true;
29+
} else {
30+
state.isShowBtn = false;
31+
}
32+
};
33+
});
34+
35+
const topFunction = (): void => {
3636
document.body.scrollTop = 0;
3737
document.documentElement.scrollTop = 0;
38-
},
38+
}
39+
40+
return {
41+
state,
42+
topFunction
43+
};
3944
},
40-
setup() {},
4145
});
4246
</script>
4347
<style scoped>

0 commit comments

Comments
 (0)