迎接崭新2026年,历时两周爆肝迭代研发 vue3.5+vant4+openai 集成 deepseek-chat 聊天大模型。新增代码高亮复制 、katex公式 及mermaid图表解析等功能。


vite7-deepseek新增代码复制 、katex数学公式 及mermaid图表功能。



使用技术
- 开发工具:Vscode
- 前端框架:vite^7.2.4+vue^3.5.24+vue-router^4.6.4
- 大模型框架:deepseek-v3.2 + openai
- 组件库:vant^4.9.21 (有赞vue3移动端组件库)
- 状态管理:pinia^3.0.4
- 代码高亮插件:highlight.js^11.11.1
- markdown解析:markdown-it
- katex公式:@mdit/plugin-katex^0.24.1
- 本地缓存:pinia-plugin-persistedstate^4.7.1

功能特性
- Vite7.2构建,接入DeepSeek-Chat模型,流式打字、性能更优、对话丝滑流畅
- 支持各种代码高亮(复制代码/收缩功能)
- 新增支持输出Katex数学公式、Mermaid图表
- 使用vant4组件库,风格统一,时尚大气
- 支持移动端+PC端750px像素适配

项目框架目录
使用vite7.2创建项目模板,集成deepseek-v3.2对话大模型,vue3 setup语法糖编码。

vue3环境变量.env

如上图:只需替换下项目根目录下 .env 文件里的key,即可畅快体验流式输出对话功能。
项目通用布局

如上图:项目整体结构分为顶部标题栏+会话区+底部编辑区三个部分。
ts
<template>
<div class="flexbox flex-col" style="height:100%;">
<Toolbar :title="chatSession?.title" />
<div class="v3ai__scrollview flex1">
<!-- Chat对话 -->
<div v-if="chatSession && !isEmpty(chatSession.data)" class="v3ai__chatbot" ref="scrollRef" @scroll="onScroll">
<div class="v3ai__chatbot-sessions">
...
</div>
<!-- 滚动底部 -->
<div class="v3ai__scrollbottom" :class="{'is-bottom': reachBottom}" @click="scrollToBottom"><i class="iconfont ai-arrD"></i></div>
</div>
<!-- 导语 -->
<div v-else class="v3ai__chatbot-intro">
<i class="logo iconfont ai-deepseek"></i>
<h3 class="name"><span class="txt text-gradient">嗨~ Vue3-DeepSeek</span></h3>
<p class="desc">你身边的智能小帮手,我可以帮你搜索、答疑、写作,请把你的任务交给我吧~</p>
<div class="prompt">
<p class="tip"><span>你可以这样问</span><span @click="refreshPrompt">换一换<i class="iconfont ai-shuaxin"></i></span></p>
<ul class="list">
<li v-for="(item,index) in promptList" :key="index">
<div class="txt" @click="changePrompt(item.prompt)">{{item.emoji}} {{item.prompt}}</div>
</li>
</ul>
</div>
</div>
</div>
<!-- 编辑器 -->
<ChatEditor ref="editorRef" :value="promptValue" :reachBottom="reachBottom" :scrollBottom="scrollToBottom" />
</div>
</template>












vue3+markdown支持katex和mermaid
在页面引入katex插件和mermaid插件。
ts
import { imgSize } from '@mdit/plugin-img-size' // 支持带尺寸图片
import { katex } from "@mdit/plugin-katex"; // 支持数学公式
import 'katex/dist/katex.min.css'
// 渲染mermaid图表
import { markdownItMermaidPlugin } from '@/components/markdown/plugins/mermaidPlugin'
在渲染组件中调用如下
ts
<Markdown
:source="item.content"
:html="true"
:linkify="true"
:typographer="true"
:plugins="[
imgSize,
[katex, {delimiters: 'all'}],
[markdownItMermaidPlugin, { ... }]
]"
@copy="onCopy"
/>
封装一个mermaid图表插件。
ts
export const markdownItMermaidPlugin = (md, options) => {
const defaultFence = md.renderer.rules.fence
md.renderer.rules.fence = (...args) => {
const [tokens, idx] = args
const token = tokens[idx]
const lang = token.info.replace(/\[.*\]/, '').trim() || ''
if(lang === 'mermaid') {
const code = token.content.trim()
const hash = generateHash(code)
const uuid = `${hash}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`
// 如果有缓存,加载缓存图表
if(renderCache.has(hash)) {
// console.log('加载缓存mermaid图表')
return `
${ defaultFence(...args) }
<div class="mermaid-container">${renderCache.get(hash)}</div>
`
}
nextTickRender(uuid)
return `
${ defaultFence(...args) }
<div class="mermaid-container" id="${uuid}" data-mermaid-hash="${hash}" data-mermaid-code="${encodeURIComponent(code)}">
<div class="mermaid-loading">📊Mermaid 图表加载中...</div>
</div>
`
}
return defaultFence(...args)
}
function nextTickRender(containerId) {
// 如果容器存在,直接渲染
if(document.getElementById(containerId)) {
renderMermaidDiagram(containerId)
return
}
// 使用MutationObserver监听DOM更新
const observer = new MutationObserver((mutations, ob) => {
const container = document.getElementById(containerId)
if(container) {
ob.disconnect()
renderMermaidDiagram(containerId)
}
})
observer.observe(document.body, {
childList: true,
subtree: true
})
}
async function renderMermaidDiagram(containerId) {
const container = document.getElementById(containerId)
if (!container) {
console.warn(`Mermaid container #${containerId} not found`)
return
}
const code = decodeURIComponent(container.dataset.mermaidCode)
const hash = container.dataset.mermaidHash
if (!code) {
return
}
// 检查 mermaid 是否可用
if (typeof window.mermaid === 'undefined') {
showError(container, 'Mermaid 库未加载!')
return
}
try {
// 配置 mermaid(如果还未配置)
if (!window.mermaid.initialized) {
window.mermaid.initialize({
startOnLoad: false,
theme: 'default',
securityLevel: 'loose',
})
window.mermaid.initialized = true
}
let svg
// 检查缓存
if(renderCache.has(hash)) {
svg = renderCache.get(hash)
}else {
const { isValid } = await verifyMermaid(code)
if(!isValid) {
showError(container, `<pre>渲染语法错误:\n${ code }\n</pre>`)
return
}
// 使用唯一ID渲染(避免图表冲突)
const {svg: renderedSvg} = await window.mermaid.render(`mermaid-${containerId}`, code)
svg = renderedSvg
renderCache.set(hash, svg)
}
// 更新容器内容
container.innerHTML = svg
container.removeAttribute('data-mermaid-hash')
container.removeAttribute('data-mermaid-code')
// 触发回调
if(options?.reachBottom) {
options?.onRender?.()
}
} catch (error) {
console.error('Mermaid 渲染失败:', error)
showError(container, `<pre>渲染图表时出错: \n ${error.message}\n</pre>`)
}
}
}
当然项目还支持运行到PC端,以750px宽度显示页面布局,也可以根据需要调整。








vue3+deepseek多轮对话和流式输出
- 实现一个上下文多轮会话
ts
const completion = await openai.chat.completions.create({
// 单一会话
/* messages: [
{role: 'user', content: editorValue}
], */
// 多轮会话
messages: props.multiConversation ? historySession.value : [{role: 'user', content: editorValue}],
model: 'deepseek-chat', // deepseek-chat对话模型 deepseek-reasoner推理模型
stream: true, // 流式输出
max_tokens: 8192, // 限制一次请求中模型生成 completion 的最大 token 数(默认使用 4096)
temperature: 0.4, // 严谨采样 越低越严谨(默认1)
})
- 流式输出对话
ts
for await (const chunk of completion) {
// 检查是否已终止
if(chatState.aborted) break
const content = chunk.choices[0]?.delta?.content
if(content) {
streamText += content
// 限制更新频率:每100ms最多更新一次
const now = Date.now()
if(now - lastUpdate > 100) {
lastUpdate = now
requestAnimationFrame(() => {
// ...
})
}
}
if(chunk.choices[0]?.finish_reason === 'stop') {
// 确保最终内容完整更新
...
}
}
Ok,以上就是vite7+vue3集成deepseek-chat实现流式ai对话的一些项目分享,希望对大家有点帮助!
基于uniapp+vue3+deepseek+markdown搭建app版流式输出AI模板
vue3.5+deepseek+arco+markdown搭建web版流式输出AI模板
2025最新款Electron38+Vite7+Vue3+ElementPlus电脑端后台admin系统
基于electron38+vite7+vue3 setup+elementPlus电脑端仿微信/QQ聊天软件
electron38.2-vue3os系统|Vite7+Electron38+Pinia3+ArcoDesign桌面版OS管理系统
2025最新版Tauri2.8+Vite7.1+Vue3+ElementPlus客户端聊天软件Exe
最新自创Tauri2.9+Vite7.1+Vue3+ElementPlus桌面端通用后台系统管理Exe模板
2025原创研发Tauri2.9+Vite7.2+Vue3+ArcoDesign客户端OS管理系统Exe
基于flutter3.32+window_manager仿macOS/Wins风格桌面os系统
flutter3.27+bitsdojo_window电脑端仿微信Exe应用
最新版Vite7+Vue3+Pinia3+ArcoDesign网页版webos后台管理系统