diff --git a/dashboard/src/components/chat/MessageList.vue b/dashboard/src/components/chat/MessageList.vue index 76dae7567..62d9fb7b9 100644 --- a/dashboard/src/components/chat/MessageList.vue +++ b/dashboard/src/components/chat/MessageList.vue @@ -485,6 +485,7 @@ export default { }, // Web search results mapping: { 'uuid.idx': { url, title, snippet } } webSearchResults: {}, + isUnmounted: false, }; }, async mounted() { @@ -496,6 +497,7 @@ export default { this.extractWebSearchResults(); }, updated() { + if (this.isUnmounted) return; this.initCodeCopyButtons(); this.initImageClickEvents(); if (this.isUserNearBottom) { @@ -915,6 +917,7 @@ export default { // 初始化代码块复制按钮 initCodeCopyButtons() { this.$nextTick(() => { + if (this.isUnmounted) return; const codeBlocks = this.$refs.messageContainer?.querySelectorAll("pre code") || []; codeBlocks.forEach((codeBlock, index) => { @@ -954,6 +957,7 @@ export default { initImageClickEvents() { this.$nextTick(() => { + if (this.isUnmounted) return; // 查找所有动态生成的图片(在markdown-content中) const images = document.querySelectorAll(".markdown-content img"); images.forEach((img) => { @@ -968,6 +972,7 @@ export default { scrollToBottom() { this.$nextTick(() => { + if (this.isUnmounted) return; const container = this.$refs.messageContainer; if (container) { container.scrollTop = container.scrollHeight; @@ -1008,6 +1013,7 @@ export default { // 组件销毁时移除监听器 beforeUnmount() { + this.isUnmounted = true; const container = this.$refs.messageContainer; if (container) { container.removeEventListener("scroll", this.throttledHandleScroll); @@ -1174,43 +1180,43 @@ export default {