增加监听URL变化
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from 'vue'
|
import { onMounted, watch } from 'vue'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
url: string
|
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> {
|
function loadWxSdk(): Promise<void> {
|
||||||
console.log('loadWxSdk')
|
console.log('loadWxSdk')
|
||||||
if (typeof window === 'undefined') return Promise.resolve()
|
if (typeof window === 'undefined') return Promise.resolve()
|
||||||
|
@@ -103,7 +103,7 @@ const links = computed(() => {
|
|||||||
const wxShareActive = ref(false)
|
const wxShareActive = ref(false)
|
||||||
// const contentRoot = ref<HTMLElement | null>(null)
|
// 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 shareTitle = computed(() => title)
|
||||||
const shareDesc = computed(() => description || title)
|
const shareDesc = computed(() => description || title)
|
||||||
const shareImg = page?.value?.img
|
const shareImg = page?.value?.img
|
||||||
|
Reference in New Issue
Block a user