Vue如何實(shí)現(xiàn)簡單的跑馬燈

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

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供舟曲網(wǎng)站建設(shè)、舟曲做網(wǎng)站、舟曲網(wǎng)站設(shè)計(jì)、舟曲網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、舟曲企業(yè)網(wǎng)站模板建站服務(wù),十年舟曲做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

內(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);//截取下標(biāo)為0的字符串
      let end = this.txt.substring(1);//截取從下標(biāo)為1到結(jié)束的字符串
      this.txt = end + start;
    },300);
   },
   stop(){
    clearInterval(this.timer)
   }
  }
 })
</script>

效果如下圖:

Vue如何實(shí)現(xiàn)簡單的跑馬燈

看完上述內(nèi)容,是不是對Vue如何實(shí)現(xiàn)簡單的跑馬燈有進(jìn)一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站題目:Vue如何實(shí)現(xiàn)簡單的跑馬燈
當(dāng)前鏈接:http://www.muchs.cn/article12/ishedc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、用戶體驗(yàn)、品牌網(wǎng)站設(shè)計(jì)、定制網(wǎng)站、網(wǎng)站改版、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)