简易明了,需要的小伙伴直接走起!
<template>
<div>
<div>
<p>{{ text }}</p>
</div>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
const shuzu = ref("欢迎来到这个世界!");
const index = ref(0);
const text = ref('');
onMounted(()=>{
setInterval(()=>{
atuoPlay()
},500)
})
const atuoPlay = () => {
index.value++;
text.value = shuzu.value.slice(0, index.value);
index.value = text.value.length === shuzu.value.length ? 0 : index.value;
};
</script>