vue3调用智谱AI实现问答模式
第一步需要再智普注册获取到对应的apikey第二步安装axios调用代码如下template div classabout h1This is an about page/h1 h1 reftypeitElement/h1 /div /template script langts setup import { ref, onMounted } from vue; import axios from axios; import TypeIt from typeit; const typeitElement ref(null); const count ref(0) onMounted(() { // POST 请求 axios.post( https://open.bigmodel.cn/api/paas/v4/chat/completions, { model: glm-4.7, messages: [ {role: user, content: 你说一下什么是vue3?} ], stream: false, temperature: 1 }, { headers: { Authorization: 2645e7242fd54513a560f1c34642916f.t3PpsikETZyPMMAP, Content-Type: application/json } }).then(response { console.log(response.data.choices[0].message.content); new TypeIt(typeitElement.value, { strings: response.data.choices[0].message.content, speed: 100, // 打字速度 loop: true, // 循环播放 breakLines: false, // 禁止换行 }).go(); }).catch(error { console.error(error) }) }) /script第三步使用插件使用 TypeIt 库安装npm install typeit使用template div h1 reftypeitElement/h1 /div /template script setup import { ref, onMounted } from vue; import TypeIt from typeit; const typeitElement ref(null); onMounted(() { new TypeIt(typeitElement.value, { strings: [欢迎来到我的博客, 这是 Vue3 的打字机效果示例。], speed: 100, // 打字速度 loop: true, // 循环播放 breakLines: false, // 禁止换行 }).go(); }); /script style scoped h1 { font-size: 2rem; color: #333; } /style