Skip to content

Commit 3bafbfb

Browse files
authored
Merge pull request #326 from InsHomePgup/feat/page
fix(theme-reco): fix the route query page
2 parents 6ea6352 + 6b8940e commit 3bafbfb

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

packages/vuepress-theme-reco/src/client/components/Home/Blog.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ import { IconFolder, IconTag } from '@components/icons/index.js'
7474
7575
const { posts, categorySummary } = useExtendPageData()
7676
77+
const total = computed(()=>{
78+
return posts.length
79+
})
80+
7781
const currentPage = ref(1)
7882
const perPage = 10
7983
@@ -111,7 +115,22 @@ if (!__VUEPRESS_SSR__) {
111115
window.scrollTo({ left: 0, top: 0, behavior: 'smooth' })
112116
}
113117
118+
const pageNum = Number(route?.query?.page)
119+
120+
function refreshPage(page){
121+
if(page>=total){
122+
page=total
123+
}else if(page<=0){
124+
page=1;
125+
}
126+
handlePagation(page);
127+
}
128+
114129
onMounted(() => {
130+
if(typeof pageNum ==='number' && !isNaN(pageNum)){
131+
refreshPage(pageNum);
132+
}
133+
115134
// @ts-ignore
116135
watch(queryPage, (newVal) => {
117136
if (newVal) {

packages/vuepress-theme-reco/src/client/components/Pagation.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,14 @@ const indexes = computed(() => {
141141
142142
const jumpPage = (page) => {
143143
const p = parseInt(page)
144-
145-
if (p <= tp.value && p > 0) {
146-
emits('change', p)
147-
return
144+
if(p>tp.value){
145+
emits('change',tp.value)
146+
}else if(p<=0){
147+
emits('change',1)
148+
}else{
149+
emits('change',p)
148150
}
149-
150-
alert(`请输入大于0,并且小于等于${tp.value}的页码!`)
151+
targetPage.value = null
151152
}
152153
153154
const goPrev = () => {

0 commit comments

Comments
 (0)