当前位置:   article > 正文

使用Vue组件vue-typed-js实现Chat_Gpt流式字幕输出效果_vuetypedjs

vuetypedjs

先看效果

20230722_111203

一、安装组件

npm install --save vue-typed-js

安装组件期间遇到的问题以及解决方案: 

以下是运行命令后的第一个报错信息:

PS G:\vx-pc\blog-friend> npm install --save vue-typed-js 

npm WARN using --force Recommended protections disabled.

npm WARN ERESOLVE overriding peer dependency

npm WARN While resolving: @vue/eslint-config-standard@6.1.0

npm WARN Found: eslint-plugin-vue@8.7.1

npm WARN node_modules/eslint-plugin-vue

npm WARN   dev eslint-plugin-vue@"^8.0.3" from the root project

npm WARN

npm WARN Could not resolve dependency:

npm WARN peer eslint-plugin-vue@"^7.0.0" from @vue/eslint-config-standard@6.1.0

npm WARN node_modules/@vue/eslint-config-standard

npm WARN   dev @vue/eslint-config-standard@"^6.1.0" from the root project

npm WARN

npm WARN Conflicting peer dependency: eslint-plugin-vue@7.20.0

npm WARN node_modules/eslint-plugin-vue

npm WARN   peer eslint-plugin-vue@"^7.0.0" from @vue/eslint-config-standard@6.1.0

npm WARN   node_modules/@vue/eslint-config-standard

npm WARN     dev @vue/eslint-config-standard@"^6.1.0" from the root project

npm ERR! code ENOENT

npm ERR! syscall spawn git

npm ERR! path git

npm ERR! errno -4058

npm ERR! enoent An unknown git error occurred

npm ERR! enoent This is related to npm not being able to find a file.

npm ERR! enoent

错误消息指示可能存在依赖项的冲突。

  1. 打开项目中的package.json文件,在dependencies 或 devDependencies 部分查找eslint-plugin-vue版本是否为7.20.0版本。如果不是请在终端中运行以下命令来更新依赖项的版本。完成后重新运行该命令:npm install --save vue-typed-js

npm install eslint-plugin-vue@7.20.0

如果你遇到的是以下报错信息:

G:\vx-pc\blog-friend> npm install --save vue-typed-js
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent An unknown git error occurred
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

这个错误通常是由于npm无法找到git的路径而引起的。这可能是因为你的计算机上没有正确设置或安装git,或者git的执行路径没有正确配置。

如果您已经正确安装了git,但npm仍然无法找到它,请确保git的可执行文件路径已正确配置到系统的PATH环境变量中。尝试重启计算机以确保新的环境变量生效。

如果你没有安装git,你可以从git的官方网站(https://git-scm.com/downloads)下载并安装最新版本的git。

配置Git后依然报同样的错误信息请使用以下办法100%解决:

桌面右键菜单项选择git bash here打开窗口运行以下几条命令:

  1. npm init -y
  2. npm i
  3. npm install vue-typed-js

二、main.js引入

  1. import Vue from 'vue'
  2. import VueTypedJs from 'vue-typed-js'
  3. Vue.use(VueTypedJs)

三、使用

  1. <template>
  2. <div>
  3. <vue-typed-js
  4. class="desc"
  5. :strings="typingTexts"
  6. :loop="true"
  7. :startDelay="300"
  8. :typeSpeed="100"
  9. :backSpeed="50"
  10. :showCursor="false"
  11. >
  12. <span class="typing"></span>
  13. </vue-typed-js>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. typingTexts: [
  21. "我可以成为任何人,但任何人不是我",
  22. "我只想做自己",
  23. ],
  24. };
  25. }
  26. };
  27. </script>

参数说明:

字符串数组要键入的字符串:strings="['Text 1', 'Text 2']"
字符串元素字符串包含字符串子元素的 ID:stringsElement="'myId'"
类型速度键入速度(以毫秒为单位):typeSpeed="50"
开始延迟键入开始之前的时间(以毫秒为单位):startDelay="1000"
回速后间距速度(毫秒):backSpeed="10"
智能退格布尔仅退格键与上一个字符串不匹配的内容:smartBackspace="true"
洗牌布尔随机播放字符串:shuffle="true"
返回延迟后退间距之前的时间(以毫秒为单位):backDelay="100"
淡出布尔淡出而不是退格:fadeOut="true"
淡出类字符串用于淡入淡出动画的 CSS 类:fadeOutClass="'fadeOutClass'"
淡出延迟淡出延迟(以毫秒为单位):fadeOutDelay="500"
布尔循环字符串:loop="true"
循环计数循环数:loopCount="3"
显示光标布尔显示光标:showCursor="true"
光标字符字符串光标的字符:cursorChar="'_'"
autoInsertCss布尔插入光标的 CSS 并淡出到 HTML 中:autoInsertCss="true"
吸引力字符串用于键入 Ex 的属性:输入占位符、值或仅输入 HTML 文本:attr="'placeholder'"
绑定输入焦点事件布尔绑定到焦点和模糊(如果 el 是文本输入):bindInputFocusEvents="true"
内容类型字符串“html”或“null”表示纯文本:contentType="'html'"

您可以收听以下事件:

事件描述用法
在完成所有键入都已完成@onComplete="doSmth()"
preStringTyped键入每个字符串之前@preStringTyped="doSmth()"
onStringTyped键入每个字符串后@onStringTyped="doSmth()"
onLastStringBackspaced在循环期间,键入最后一个字符串之后@onLastStringBackspaced="doSmth()"
onTyping暂停键入已停止@onTypingPaused="doSmth()"
onTyping已恢复停止键入后已开始键入@onTypingResumed="doSmth()"
复位时复位后@onReset="doSmth()"
停止停止后@onStop="doSmth()"
在开始启动后@onStart="doSmth()"
销毁销毁后@onDestroy="doSmth()"

最后附一下 vue-typed-js这个插件的地址:GitHub - Orlandster/vue-typed-js: Typed.js integration for vue.js. Create a typing animation.

总得来说,挺好用的。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/880260
推荐阅读
相关标签
  

闽ICP备14008679号