js 文字逐个弹出
data: 中定义contex:‘’
created中调用showText,
参数:‘需要逐个弹出的文字’
methods:
// 文字逐个出现
showText(text){
this.context = '';
var speed = 200 ;//定时的速度
var count = 1;
clearTimeout(this.timer)
this.context = this.changeContent(text,speed,count)
},
// 文字逐个出现 text:文字 speed 定时的速度
changeContent(text,speed,count){
var num = count;
const _this = this;
this.context = text.substring(0,num)
num++;
if(num < text.length+1){
this.timer = setTimeout(() => {
_this.changeContent(text,speed,num)
}, speed);
}
},