<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
{{str2}}
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
str: '上古结绳而治,后世圣人易之以书契。千年来,数据始终影响着人们的生活。人类一直在探索,大数据时代来临之时使用何种工具用于改变用户利用数据的方式。',
i: 0,
timer: 0,
str2: "",
},
methods: {
typing() {
if (this.i <= this.str.length) {
this.str2 = this.str.slice(0, this.i++) + '_';
this.timer = setTimeout(() => {
this.typing();
}, 200);
} else {
clearTimeout(this.timer)
}
}
},
mounted() {
this.typing();
}
})
</script>
</body>
</html>