聊天助手ai回答内容换行符转换

This commit is contained in:
xuxin
2026-05-28 15:00:30 +08:00
parent 3dbeddcb8f
commit e34bb2a21e
+8 -1
View File
@@ -44,7 +44,7 @@
class="ai-chat__msg" class="ai-chat__msg"
:class="msg.role === 'assistant' ? 'ai-chat__msg--ai' : 'ai-chat__msg--user'" :class="msg.role === 'assistant' ? 'ai-chat__msg--ai' : 'ai-chat__msg--user'"
> >
<div class="ai-chat__msg-bubble" v-html="msg.content"></div> <div class="ai-chat__msg-bubble" v-html="formatContent(msg.content)"></div>
</div> </div>
<!-- AI 正在思考中加载指示器 --> <!-- AI 正在思考中加载指示器 -->
@@ -178,6 +178,13 @@ const quickQuestions = computed(() => {
/** 用户提问列表(等同于 quickQuestions */ /** 用户提问列表(等同于 quickQuestions */
const userQuestions = computed(() => quickQuestions.value) const userQuestions = computed(() => quickQuestions.value)
// ==================== 内容格式化 ====================
/** 将消息中的换行符转为 HTML 换行标签 */
function formatContent(content: string): string {
return content.replace(/\n/g, '<br>')
}
// ==================== 滚动控制 ==================== // ==================== 滚动控制 ====================
/** 滚动到聊天区域底部 */ /** 滚动到聊天区域底部 */