Skip to content

Commit 5294cb6

Browse files
committed
fix: window scroll
1 parent 52d16e1 commit 5294cb6

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

layouts/Category.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default {
5555
posts.sort((a, b) => {
5656
return this._getTimeNum(b) - this._getTimeNum(a)
5757
})
58-
this.getCurrentPage(1)
58+
this._setPage(1)
5959
return posts
6060
},
6161
// 标题只显示分类名称
@@ -75,6 +75,12 @@ export default {
7575
},
7676
// 获取当前页码
7777
getCurrentPage (page) {
78+
this._setPage(page)
79+
setTimeout(() => {
80+
window.scrollTo(0, 0)
81+
}, 100)
82+
},
83+
_setPage (page) {
7884
this.currentPage = page
7985
this.$page.currentPage = page
8086
},

layouts/Tags.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:key="index"
88
:class="{'active': item.name == currentTag}"
99
:style="{ 'backgroundColor': item.color }"
10-
@click="getPagesByTags(item.name)">{{item.name}}</span>
10+
@click="tagClick(item.name)">{{item.name}}</span>
1111
</div>
1212
<note-abstract
1313
class="list"
@@ -79,6 +79,15 @@ export default {
7979
8080
methods: {
8181
82+
initData (currentTag) {
83+
this.getPagesByTags(currentTag)
84+
},
85+
86+
async tagClick (currentTag) {
87+
await this.getPagesByTags(currentTag)
88+
window.scrollTo(0, 0)
89+
},
90+
8291
// 根据分类获取页面数据
8392
getPagesByTags (currentTag) {
8493
this.currentTag = currentTag
@@ -96,19 +105,23 @@ export default {
96105
// reverse()是为了按时间最近排序排序
97106
this.posts = posts.length == 0 ? [] : posts
98107
99-
this.getCurrentPage(1)
108+
this._setPage(1)
100109
},
101110
102111
getCurrentTag (tag) {
103112
this.$emit('currentTag', tag)
104113
},
105114
106115
getCurrentPage (page) {
116+
this._setPage(page)
117+
setTimeout(() => {
118+
window.scrollTo(0, 0)
119+
}, 100)
120+
},
121+
_setPage (page) {
107122
this.currentPage = page
108123
this.$page.currentPage = page
109-
window.scrollTo(0, 0)
110124
},
111-
112125
// 获取时间的数字类型
113126
_getTimeNum (date) {
114127
return parseInt(new Date(date.frontmatter.date).getTime())

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuepress-theme-reco",
3-
"version": "1.0.9-alpha.3",
3+
"version": "1.0.9-alpha.6",
44
"description": "this is a vuepress theme",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)