+
80
-

uniapp如何实现文字打字输出效果?

uniapp如何实现文字打字输出效果?


网友回复

+
0
-

<template>
<view>{{teststr}}</view>
</template>
<script>
let that;
export default {
		data() {
			return {
				textWriter:'你好啊你好啊你好啊你好啊你好啊我是chatgpt',
				teststr:'',
			}
		},
		onLoad() {
			that = this;
			that.setData();
		},
		methods: {
			//js打字效果
			setData(){
				let i = 0;
				let timer = setInterval(function(){
						if (i <= that.textWriter.length) {
					    that.teststr = that.textWriter.slice(0, i++) + '_'
						}
						else {
							that.teststr = that.textWriter
							clearInterval(timer)
						}
				}, 30)

			},
		}
	}
</script>

我知道答案,我要回答