uni-app 实现打字机效果(逐个显示文本)
作者:
Jeex | 来源:发表于
2023-06-29 14:56 被阅读0次<template>
<view>
<text>{{ typedText }}</text>
</view>
</template>
<script>
export default {
data() {
return {
text: "Hello, World!",
typedText: ""
};
},
mounted() {
this.startTyping();
},
methods: {
startTyping() {
let currentIndex = 0;
const typingSpeed = 100; // 打字速度,单位:毫秒
const timer = setInterval(() => {
this.typedText += this.text[currentIndex];
currentIndex++;
if (currentIndex >= this.text.length) {
clearInterval(timer);
}
}, typingSpeed);
}
}
};
</script>
本文标题:uni-app 实现打字机效果(逐个显示文本)
本文链接:https://www.haomeiwen.com/subject/hooaydtx.html
网友评论