文本打字机 - 文本以打字机形式一个个显示

https://blog.csdn.net/qq_41993503/article/details/107640238

<p class='typewriter'>{{typewriter}}</p>
data () {
    return {
      typewriter: '',
      i: 0,
      timer: 0,
      str: 'Hi, i´m a web Designer'
    }
}
mounted () {
  this.typeing()
},
methods: {
  typeing () {
    if (this.i <= this.str.length) {
      this.typewriter = this.str.slice(0, this.i++) + '_'
      this.timer = setTimeout(() => {
        this.typeing()
      }, 150)
   } else {
      clearTimeout(this.timer)
   }
 }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容