增加监听URL变化
Some checks failed
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled

This commit is contained in:
2025-08-09 13:37:57 +08:00
parent 597339b666
commit 046b0ef674
2 changed files with 14 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import { onMounted, watch } from 'vue'
const props = defineProps<{
url: string
@@ -22,6 +22,18 @@ onMounted(async () => {
}
})
// 路径变化时,重新获取签名并刷新分享数据(适配 SPA 场景)
watch(() => props.url, async (newUrl, oldUrl) => {
if (!newUrl || newUrl === oldUrl) return
try {
await loadWxSdk()
const { appId, timestamp, nonceStr, signature } = await getWxConfig()
setupShare(appId, timestamp, nonceStr, signature)
} catch (err) {
console.error('[WxShare] reconfig error:', err)
}
})
function loadWxSdk(): Promise<void> {
console.log('loadWxSdk')
if (typeof window === 'undefined') return Promise.resolve()

View File

@@ -103,7 +103,7 @@ const links = computed(() => {
const wxShareActive = ref(false)
// const contentRoot = ref<HTMLElement | null>(null)
const shareLink = 'https://lijue.me' + decodeURIComponent(path.value)
const shareLink = computed(() => 'https://lijue.me' + decodeURIComponent(path.value))
const shareTitle = computed(() => title)
const shareDesc = computed(() => description || title)
const shareImg = page?.value?.img