vue实现自动打字效果(带光标效果)

代码介绍(其实就是通过字符串截取加定时拼接完成的,我相信有时间都能琢磨出来,来这里就是为了省事)

上vue页面代码:

javascript 复制代码
<template>
  <div id='App'>
    <h2>{{text}}<span ref="fou" class="fousdis">{{'_'}}</span></h2>
  </div>
</template>
<script>
export default {
  name: 'App',
  data() {
    return {
      initialText: '这是一个打字教程打字教程,。,。,777',
      index: 0,
      text: ''
    }
  },
  mounted() {
    setInterval(() => {
      this.autoTyping()
      var tim = setInterval(() => {
              this.$refs.fou.classList.toggle('fousdis')
               if (this.index === this.text.length) {
                    clearInterval(tim)
                      }
            }, 150)
    }, 300)
  },
  methods: {
    autoTyping() {
      this.index++
      this.text = this.initialText.slice(0, this.index)
      // this.index = this.text.length === this.initialText.length ? 0 : this.index  //实现循环打字
    }
  }
}
</script>
<style >
.fousdis{
  display: none;
}
</style>

老规矩:复制粘贴那去看效果

相关推荐
哇嘎呀几秒前
RHCSA题目
java·服务器·前端
周厉22 分钟前
ERP系统全景解析:核心模块与业务逻辑框架
java·服务器·前端
LEE37 分钟前
为什么你的 Claude Code 还在转圈等,别人的已经干完三件事了?
前端·后端·ai编程
java1234_小锋1 小时前
【技术专题】HTML5 网页技术 - HTML5 SVG
前端·html·html5
飞飞鱼在摸鱼1 小时前
前端转Agent开发 | JavaScript 从 0 到 1 完全指南
前端·javascript
开开心心就好1 小时前
课堂随机点名工具,绿色版免安装双击即用
java·服务器·前端·ffmpeg·音视频·perl·symfony
不像程序员的程序媛1 小时前
springboot支持的web容器
前端·spring boot·后端
xiaobaoyu1 小时前
目录合集
前端
han_hanker1 小时前
前端转后端入门实践日志2-nacos
前端
Suprman1 小时前
从 B/S 到 Electron:平面排版套料系统桌面版开发实战
javascript·平面·electron·排序算法