<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="app">
<input type="button" value = "浪" v-on:click="lang" >
<input type="button" value = "停" v-on:click="stop" >
<p>{{ msg }}</p>
</div>
<script>
new Vue(
{
el: '#app',
data: {
msg: '你要完蛋了!',
intervalId: null
},
methods: {
lang(){
if(this.intervalId != null) return;
this.intervalId = setInterval( () => {
var start = this.msg.substring(0,1)
var end = this.msg.substring(1)
this.msg = end + start
},400)
},
stop() {
clearInterval(this.intervalId),
this.intervalId = null
}
}
}
)
</script>
</body>
</html>