• 老样子,话不多说,直接上代码
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.css" rel="stylesheet">
    <title>Document</title>
</head>
<body>
	<div id="app">
		<button class="btn btn-primary" @click="running">running</button>
		<button class="btn btn-primary" @click="stop">stop</button>
		<h3>{{message}}</h3>
	</div>
	<!--引入自己的Vue地址-->
	<script src="vue.js"></script>
	<script>
		const app = new Vue({
			el:"#app",
			data:{
				message:'但屈指西风几时来,又不道流年暗中偷换.',
				interval:null
			},
			methods:{
				running(){
					if(this.interval == null) {
						this.interval = setInterval(function(){
							let start = this.message.substring(0,1);
							let end = this.message.substring(1);
							this.message = end + start;
						},500)
					}
				},
				stop(){
					clearInterval(this.interval)
					this.interval = null
				}
			}
		})
	</script>
</body>
</html>
Logo

前往低代码交流专区

更多推荐