Skip to content

Commit a359485

Browse files
committed
优化组件缓存
1 parent 7e33e0e commit a359485

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

src/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</header>
1212
<main>
1313
<transition appear :name="pageTransitionName">
14-
<keep-alive :exclude="['resume','resume-editor',]" :max="30">
14+
<keep-alive :exclude="['resume','resume-editor','job']" :max="30">
1515
<router-view :key="$route.path"></router-view>
1616
</keep-alive>
1717
</transition>
@@ -118,8 +118,8 @@ footer {
118118
margin-top: 100px;
119119
}
120120
121-
#app,
122-
main {
121+
header {
123122
position: relative;
123+
z-index: 1000;
124124
}
125125
</style>

src/helper/utilities.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const watchScrollDirection = function(scrollElement, callback) {
44
directionX: 1,
55
directionY: 1,
66
};
7-
7+
let previousTimer;
88
function onScroll(e) {
99
const scrollTop = scrollElement.scrollTop || scrollElement.pageYOffset;
1010
const scrollLeft = scrollElement.scrollLeft || scrollElement.pageXOffset;
@@ -19,12 +19,21 @@ export const watchScrollDirection = function(scrollElement, callback) {
1919
} else {
2020
scrollDirection.directionX = 1;
2121
}
22+
2223
callback.call(scrollElement, scrollDirection, scrollPos);
2324

2425
scrollPos.x = scrollLeft;
2526
scrollPos.y = scrollTop;
2627
}
27-
scrollElement.addEventListener("scroll", onScroll);
28+
29+
scrollElement.addEventListener("scroll", () => {
30+
let now = Date.now();
31+
if (!previousTimer) previousTimer = now;
32+
if (now - previousTimer > 100) {
33+
onScroll();
34+
previousTimer = now;
35+
}
36+
});
2837
return function() {
2938
scrollElement.removeEventListener("scroll", onScroll);
3039
};
@@ -60,7 +69,7 @@ export function formatDate(date, format = true) {
6069

6170
export function getOffsetTop(relativeNode, node, topSum = 0) {
6271
topSum += node.offsetTop;
63-
72+
6473
if (node.offsetParent !== relativeNode) {
6574
return getOffsetTop(relativeNode, node.offsetParent, topSum);
6675
}

src/views/Home.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ export default {
240240
{ x: document.body.scrollLeft, y: document.body.scrollTop }
241241
);
242242
this.unwatch = watchScrollDirection(window, function(...args) {
243+
243244
rootVm.$emit("home-scrolling", ...args);
244245
});
245246
},

src/views/Jobs.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ let searchBarClientHeight = 0;
7272
export default {
7373
name: "job",
7474
data() {
75+
const { keyword, job_category_id } = this.$route.params;
7576
return {
76-
searchKeyword: "",
77+
searchKeyword: keyword || "",
7778
currentPage: 1,
78-
job_category_id_list: [],
79+
job_category_id_list: job_category_id ? [job_category_id] : [],
7980
jobCategories: [],
8081
jobCities: [],
8182
location_code_list: [],
@@ -87,12 +88,6 @@ export default {
8788
};
8889
},
8990
90-
activated() {
91-
this.searchKeyword = this.$route.params.keyword || "";
92-
if (this.$route.params.job_category_id) {
93-
this.job_category_id_list = [this.$route.params.job_category_id];
94-
}
95-
},
9691
created() {
9792
const jobConfigRequest = this.request
9893
.get("/job-filters")
@@ -113,10 +108,13 @@ export default {
113108
this.$nextTick(() => {
114109
positionY = getOffsetTop(document.body, this.$refs.searchBar);
115110
searchBarClientHeight = this.$refs.searchBar.clientHeight;
116-
117111
});
118112
},
119113
activated() {
114+
this.searchKeyword = this.$route.params.keyword || "";
115+
if (this.$route.params.job_category_id) {
116+
this.job_category_id_list = [this.$route.params.job_category_id];
117+
}
120118
const onPageScroll = () => {
121119
const top = this.$refs.searchBar.getBoundingClientRect().top;
122120
@@ -127,6 +125,8 @@ export default {
127125
128126
this.$on("hook:deactivated", () => {
129127
window.removeEventListener("scroll", onPageScroll);
128+
// this.clearFilter();
129+
// this.searchKeyword = "";
130130
});
131131
},
132132
computed: {

0 commit comments

Comments
 (0)