console
var vm = new Vue({
el: '#app',
data:{
typewriter: '',
i: 0,
timer: 0,
str: 'Hi,this is a test.'
},
mounted () {
this.typeing()
},
methods: {
typeing () {
if (this.i <= this.str.length) {
this.typewriter = this.str.slice(0, this.i++)
this.timer = setTimeout(() => {
this.typeing()
}, 200)
} else {
clearTimeout(this.timer)
}
}
}
});
<div id="app">
<p class="typewriter">{{ typewriter }}</p>
</div>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}