实现方式:开始文字设置为空 ,然后通过添加定时器截取content字符串来实现。
效果展示如下:
具体实现如下:
<template>
<div>
<div v-html=“showText ”></div>
</div>
</template>
<script>
export default {
data() {
return {
timer: null, //settimeout
showText: "",
};
},
mounted() {
this.appear(
);
},
methods: {
appear(content) {
const _this = this;
this.showText = "";
clearTimeout(this.timer);
var speed = 50; //设置定时的速度 越来越快
var count = 1;
content = content.replace(/\/n/g,'<br/>');
function changeContent() {
_this.showText = content.substring(0, count); //截取字符串
count++;
if (count != content.length + 1) {
speed -= 1;
if (speed < 5) speed = 5;
_this.timer = setTimeout(changeContent, speed);
}
}
changeContent();
},
},
};
</script>
来源链接:https://blog.csdn.net/sunnywuxian/article/details/124999549
标签:count,changeContent,vuejs,timer,content,换行,showText,逐个,speed From: https://www.cnblogs.com/wangyan0926/p/17335704.html