
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<p>{{msg}}</p>
<button type="button" @click="run()">飄</button>
<button type="button" @click="stop()">停</button>
</div>
<script type="text/javascript">
new Vue({
el:"#app",
data:{
msg:"晚星就像你的眼睛,殺人又放火·········",
ind:null,//停止定時器標識
},
methods:{
run(){
if(this.ind){return};
this.ind=setInterval(()=>{
var arr = this.msg.split('');
//shift 洗掉并回傳陣列的個數
// push 添加最后面
// 把陣列的第一個元素放在后面
arr.push(arr.shift());
// arr.join() 把陣列連接為字串復制給msg
this.msg=arr.join('');
},100)
},
stop(){
// 清除定時器
clearInterval(this.ind);
//設定ind為null
this.ind =null;
}
}
})
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/345772.html
標籤:其他
下一篇:【JavaScript】垃圾回收
