@sugarat/theme 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "vitepress-plugin-mermaid": "2.0.13",
53
53
  "vitepress-plugin-tabs": "0.2.0",
54
54
  "vitepress-plugin-pagefind": "0.2.14",
55
- "vitepress-plugin-rss": "0.2.3"
55
+ "vitepress-plugin-rss": "0.2.4"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@element-plus/icons-vue": "^2.3.1",
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, watch } from 'vue'
2
+ import { computed, onMounted } from 'vue'
3
3
  import { ElPagination } from 'element-plus'
4
4
  import { useData, useRouter } from 'vitepress'
5
5
  import { useBrowserLocation } from '@vueuse/core'
@@ -60,32 +60,34 @@ function handleUpdatePageNum(current: number) {
60
60
  if (currentPage.value === current) {
61
61
  return
62
62
  }
63
- currentPage.value = current
64
63
  const { searchParams } = new URL(window.location.href!)
65
64
  searchParams.delete(queryPageNumKey)
66
65
  searchParams.append(queryPageNumKey, String(current))
66
+ window.scrollTo({ top: 0, behavior: 'auto' })
67
67
  router.go(
68
- `${location.value.origin}${router.route.path}?${searchParams.toString()}`
68
+ `${router.route.path}?${searchParams.toString()}`
69
69
  )
70
70
  }
71
71
 
72
- watch(
73
- location,
74
- () => {
75
- if (location.value.href) {
76
- const { searchParams } = new URL(location.value.href)
77
- if (searchParams.has(queryPageNumKey)) {
78
- currentPage.value = Number(searchParams.get(queryPageNumKey))
79
- }
80
- else {
81
- currentPage.value = 1
82
- }
72
+ function refreshCurrentPage(search?: string) {
73
+ if (location.value?.href) {
74
+ const searchParams = new URLSearchParams(search || location.value.search)
75
+ const pageNum = Number(searchParams.get(queryPageNumKey)) || 1
76
+ if (pageNum !== currentPage.value) {
77
+ currentPage.value = pageNum
83
78
  }
84
- },
85
- {
86
- immediate: true
87
79
  }
88
- )
80
+ }
81
+ router.onBeforeRouteChange = (to) => {
82
+ refreshCurrentPage(to.slice(to.indexOf('?') + 1))
83
+ }
84
+ // 未覆盖的场景处理
85
+ router.onAfterRouteChanged = (to) => {
86
+ refreshCurrentPage(to.slice(to.indexOf('?') + 1))
87
+ }
88
+ onMounted(() => {
89
+ refreshCurrentPage()
90
+ })
89
91
  </script>
90
92
 
91
93
  <template>