当前位置: 首页 > news >正文

免费信息发布网站有哪些安徽建设工程有限公司

免费信息发布网站有哪些,安徽建设工程有限公司,定制化网站建设,绑定网站在现代前端开发中,添加一些视觉效果可以提升用户体验。其中,打字机效果是一种常见且吸引人的效果,可以用于展示动态文本。本文将介绍如何在 Vue 3 中实现打字机效果。 实现步骤 1. 创建自定义指令 我们首先创建一个自定义指令 v-typewriter…

在现代前端开发中,添加一些视觉效果可以提升用户体验。其中,打字机效果是一种常见且吸引人的效果,可以用于展示动态文本。本文将介绍如何在 Vue 3 中实现打字机效果。

实现步骤

1. 创建自定义指令

我们首先创建一个自定义指令 v-typewriter,用于实现打字机效果。这个指令将逐字显示绑定的文本内容。

const typeWriter = ref(null);const typewriterDirective = (el, binding) => {const indexValue = el.getAttribute('data-index');const delay = 150; // 设置延迟时间,默认150mslet i = 0;typeWriter.value = setInterval(() => {if (binding?.value && i < binding.value.length) {if (textList.value && textList.value[indexValue]) {textList.value[indexValue].typewriterText += binding.value.charAt(i) || '';}i++;} else {clearInterval(typeWriter.value);stop(textList.value[indexValue], indexValue, true);}}, delay);
};const vTypewriter = {mounted(el, binding) {typewriterDirective(el, binding);}
};

2. 使用自定义指令

在 Vue 组件中使用自定义指令 v-typewriter。该指令会在元素挂载时自动触发,逐字显示文本内容。

<template><div class="left-content mr-16"><el-scrollbar ref="scrollRef" height="100%" class="scroll"><div class="flex mb-48" v-for="(item, index) in textList" :key="item.updateKey"><div class="user-avatar"><img v-if="item.resultTts || item.library" src="/img/avatar.png" alt="" /><img v-else src="/img/user_avatar.png" alt="" /></div><div class="ml-12"><div class="time mb-11"><span v-if="item.resultTts || item.library">智能馆员{{ item.time }}</span><span v-else>读者{{ item.time }}</span></div><div><divclass="answer":class="item.resultTts || item.library ? 'libarary-bg' : 'user-color '"><div v-if="item.resultTts || item.library"><van-loading v-if="!item.resultMessage" type="spinner" color="#1989fa" /><div v-if="item.isStop && item.stopText">{{ item.stopText }}</div><divv-if="item.resultTts && !item.isStop"v-typewriter="item.resultTts":data-index="index">{{ item.typewriterText }}</div></div><div v-else>{{ item.resultMessage }}</div></div><divv-if="(!item.isStop && item.resultTts) || !item.resultMessage"class="stop-icon mt-18"@click="stop(item, index)">停止生成</div></div><BookListv-if="item.dataList?.length && item.isStop":data-list="item.dataList"></BookList></div></div></el-scrollbar></div>
</template><script>
import { ref } from 'vue';
import { useEventBus } from '@/hooks/useEventBus';const emits = defineEmits(['watchTypeWriter', 'handleStop']);const textList = ref([]);
useEventBus('clearChatInfo', () => {textList.value = [];
});
useEventBus('changeAction', (message) => {
// message其它组件传递的数据 clearInterval(typeWriter.value);if (!textList.value.length || !message.resultTts) {textList.value.push({time: ` ${dayjs().format('HH:mm:ss')}`,isStop: false,  // 是否停止stopText: '',   // 打字机停止后的内容typewriterText: '',  // 动态展示打字机内容的文本updateKey: dayjs().valueOf(), // 每次增加一条数据的唯一key...message});return;}if (textList.value.length && message.resultTts) {textList.value[textList.value.length - 1] = {...textList.value[textList.value.length - 1],...message};}
});const stop = (item, index, isFinish = false) => {if (!item.resultMessage) {item.isStop = true;emits('handleStop');return;}if (item.isStop) {return;}const curText = document.querySelector(`[data-index="${index}"]`);item.isStop = true;item.stopText = curText?.innerText;
};
</script><style scoped lang="scss">
/* 自定义样式*/
</style>
http://www.yayakq.cn/news/51095/

相关文章:

  • 怎么做网站的浏览量wordpress resetpass
  • 做网站公司上班违法吗wordpress上下页翻页
  • 西安网站建设排行榜柳州 网站建设
  • 网站建设规划书主题东莞怎么建设网站公司
  • 地方门户网站策划书宁波seo排名方案
  • 冠县网站建设公司扫码员在哪个网站可以做
  • 唐山市住房房和城乡建设厅网站栾城网站建设
  • 为什么做电影网站没有流量吗宁波网络关键词优化费用
  • 设计公司网站 唐山windows做的ppt下载网站
  • 新手学网站建设内丘网站
  • 济南住房和城乡建设厅网站网站登录后不显示内容
  • h5做商城网站wordpress 视频 插件
  • 北京网站主题制作哪个网站可以做excel
  • 建设企业网站公司在哪里重庆seo排名收费
  • 苏州吴中区建设局工程网站柯桥网站建设
  • 成都响应网站建设帮人做网站收多少钱
  • 做室内设计人喜欢的网站免费源码大全无用下载
  • 贵阳模板建站定制手机软件怎么写出来的啊
  • 做网站送邮箱单位网站设计制作
  • 网站开发实战 王徐州网站制作费用
  • 选择网站做友情链接的标准一般是如何查询商标是否已经被注册
  • 无锡网站制作电话睿思设计
  • 网站google排名出现过几分钟定制网站开发哪家好
  • 重庆市建设厅网站首页学校ui设计培训
  • 第三方平台网站的建设规划安装宝塔之后wordpress首页打不开
  • 兰州专业做网站的公司有哪些内蒙古高等级公路建设开发有限责任公司网站
  • 做整站优化呼叫中心系统源码
  • 涉县移动网站建设推广网站概况
  • 做现货黄金网站凡客集团
  • 给人做网站网站犯法嘛手机网站开发 视频教程