From 3e910e14a4b136bda3a0ef42aba7474e9ed04860 Mon Sep 17 00:00:00 2001 From: kjqwer <2990346238@qq.com> Date: Sat, 6 Sep 2025 10:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E4=B8=8D=E5=AE=9E=E6=97=B6=E6=9B=B4=E6=96=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/components/common/WatchlistWidget.vue | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/src/components/common/WatchlistWidget.vue b/ui/src/components/common/WatchlistWidget.vue index ffaac45..c12b8c5 100644 --- a/ui/src/components/common/WatchlistWidget.vue +++ b/ui/src/components/common/WatchlistWidget.vue @@ -255,15 +255,17 @@ const getCurrentPageUrl = () => { return window.location.href; }; +// 当前页面URL的响应式变量 +const currentPageUrl = ref(getCurrentPageUrl()); + // 检查当前页面是否已添加 const isCurrentPageAdded = computed(() => { - const currentUrl = getCurrentPageUrl(); - return watchlistStore.hasUrl(currentUrl); + return watchlistStore.hasUrl(currentPageUrl.value); }); // 检查是否为当前URL const isCurrentUrl = (url: string) => { - const currentUrl = getCurrentPageUrl(); + const currentUrl = currentPageUrl.value; // 直接比较完整URL if (currentUrl === url) { @@ -354,12 +356,11 @@ const addCurrentPage = async () => { if (addLoading.value || isCurrentPageAdded.value) return; addLoading.value = true; - const currentUrl = getCurrentPageUrl(); + const currentUrl = currentPageUrl.value; try { const success = await watchlistStore.addItem({ url: currentUrl }); if (success) { - // 可以添加一个成功提示 console.log('页面已添加到待看名单'); } } finally { @@ -550,9 +551,10 @@ onMounted(() => { fetchItems(); }); -// 监听路由变化,更新当前页面状态 +// 监听路由变化,更新当前页面URL watch(() => route.fullPath, () => { - // 路由变化时可能需要更新当前页面的状态 + // 路由变化时更新当前页面URL + currentPageUrl.value = getCurrentPageUrl(); });