這篇文章主要講解了Vue如何實現(xiàn)簡單的跑馬燈,內(nèi)容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。

內(nèi)容不多,直接看代碼吧
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../../資料/js/vue.js"></script> <!-- 引入Vue-->
</head>
<style>
*{
text-align: center;
}
</style>
<body>
<div id="app">
<h2>{{txt}}</h2>
<button @click="run">開始</button>
<button @click="stop">停止</button>
</div>
</body>
</html>
<script>
new Vue({
el:'#app',
data:{
txt:"吾疑君馭車而飚之,然苦于無證以示眾。",
timer:null
},
methods:{
run(){
if(this.timer != null){
return;
}
this.timer = setInterval(()=>{
let start = this.txt.substring(0,1);//截取下標為0的字符串
let end = this.txt.substring(1);//截取從下標為1到結(jié)束的字符串
this.txt = end + start;
},300);
},
stop(){
clearInterval(this.timer)
}
}
})
</script>
網(wǎng)頁標題:Vue如何實現(xiàn)簡單的跑馬燈-創(chuàng)新互聯(lián)
本文鏈接:http://www.chinadenli.net/article40/dpcseo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、品牌網(wǎng)站設(shè)計、云服務(wù)器、域名注冊、網(wǎng)站設(shè)計公司、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容