<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>VUE 跑马灯</title>
<script type="text/javascript" src="./js/vue.js"></script>
</head>
<body>
<div id="h1">
<input type="button" value="start" v-on:click="onStartClick">
<input type="button" value="stop" @click="onStopClick">
<h3 v-text="msg"></h3>
</div>
<script>
var vm = new Vue({
el:"#h1",
data:{
msg:"跑马灯效果,跑起来",
muInterval: null
},
methods: {
onStartClick(){
if(this.myInterval) return
this.myInterval = setInterval(()=>{
var firstChar = this.msg.substring(0,1)
var otherChars = this.msg.substring(1)
this.msg = otherChars+firstChar
},300)
},
onStopClick(){
if(this.myInterval){
clearInterval(this.myInterval)
this.myInterval = null
}
}
}
})
</script>
</body>
</html>