2027最新版vite7.2+vue3.5+deepseek-v3.2+markdown实战高颜值流式AI对话模板 - const container = document
迎接即将到来2026最新爆肝新作Vite7+DeepSeek-V3.2+Vant4+OpenAI流式打字输出AI小助手。
vite7-deepseek-chat:基于vue3.5+vite7.2+vant4+markdown+openai接入deepseek-v3.2聊天大模型。支持浅色+深色主题、流式打字输出、代码高亮、复制代码、katex数学公式、mermaid图表等功能。
使用技术
开发工具:Vscode前端框架:vite7.2.4+vue3.5.24+vue-router4.6.4大模型框架:deepseek-v3.2 + openai组件库:vant^4.9.21 (有赞vue3移动端组件库)状态管理:pinia^3.0.4高亮插件:highlight.js^11.11.1markdown解析:markdown-itkatex公式:@mdit/plugin-katex^0.24.1本地缓存:pinia-plugin-persistedstate^4.7.1
项目特色
最新Vue3.5+DeepSeek-V3.2流式打字输出效果基于Vite7.2构建,集成DeepSeek-Chat模型,性能更优,对话丝滑流畅支持各种代码高亮(复制代码/收缩功能),方便展示和分享代码片段支持输出Katex数学公式、Mermaid图表使用vant4组件库,风格统一,时尚大气支持移动端+PC端750px像素适配
项目框架目录
使用最新款vite7.2+deepseek-v3.2创建项目模板,vue3 setup语法开发页面。
vite7-deepseek流式ai对话助手已经更新到我的原创作品集。 Vue3+DeepSeek+Vant4智能聊天AI流式对话模板
环境变量配置.env
# title
VITE_APP_TITLE = 'Vue3-DeepSeek-Chat'
# port 默认http://localhost:5173/
VITE_PORT = 3001
# 运行时自动打开浏览器
VITE_OPEN = true
# 开启https
VITE_HTTPS = false
# 是否删除生产环境 console
VITE_DROP_CONSOLE = true
# DeepSeek API配置
VITE_DEEPSEEK_API_KEY = 替换为你的 API Key
VITE_DEEPSEEK_BASE_URL = https://api.deepseek.com
入口配置main.js
import { createApp } from 'vue'
import './style.scss'
import App from './App.vue'
// 引入路由/状态管理
import Router from './router'
import Pinia from './pinia'
import Plugins from './plugins'
const app = createApp(App)
app
.use(Router)
.use(Pinia)
.use(Plugins)
.mount('#app')
项目公共模板
如上图:分为顶部导航栏+聊天会话区+底部编辑栏三部分。
引入katex公式和mermaid图表
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'
在组件中使用。
:source="item.content"
:html="true"
:linkify="true"
:typographer="true"
:plugins="[
imgSize,
[katex, {delimiters: 'all'}],
[markdownItMermaidPlugin, { ... }]
]"
@copy="onCopy"
/>
封装一个mermaid自定义图表组件。
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) }
`
}
nextTickRender(uuid)
return `
${ defaultFence(...args) }
`
}
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, `
渲染语法错误:\n${ code }\n
`)
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, `
渲染图表时出错: \n ${error.message}\n
`)
}
}
}
另外还支持运行在PC网页端,以750px宽度展示页面布局。
vue3接入deepseek流式
支持上下文多轮会话模式。
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)
})
处理流式输出。
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+deepseek搭建移动端流式输出ai对话项目的一些分享,感谢大家的阅读与支持!
往期推荐
2025最新款Tauri2.9+Vite7.2+Vue3 setup+ArcoDesign电脑版os后台解决方案 基于tauri2+vite7.1+vue3 setup+pinia3+element-plus电脑端聊天系统 Tauri2-Vite7Admin客户端管理后台|tauri2.9+vue3+element-plus后台系统 基于Electron38.2+Vite7+Vue3+ArcoDesign客户端OS系统 Electron38-Vue3Chat电脑端聊天|vite7+electron38+pinia3仿微信 最新款Electron38+Vue3+Vite7+ElementPlus客户端中后台管理系统 基于uni-app+vue3+pinia2+uv-ui仿抖音app短视频+聊天+直播商城系统 基于uni-app+vue3+deepseek+uv-ui仿DeepSeek流式AI聊天模板 基于Vite6+Deepseek+ArcoDesign+Markdown构建网页版AI流式 最新版vite7-vue3-webos网页版仿macos系统|Vite7+Pinia3+Arco网页os 2025跨端uniapp+vue3+uv-ui实战仿微信app聊天模板 基于uniapp+vue3跨端手机admin管理系统uniapp-vue3os 基于flutter3.32+window_manager+get仿macOS/wins桌面os系统 最新flutter3.27+get+bitsdojo_window电脑版仿微信聊天EXE,2027最新版vite7