国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

Vue計時(shí)器的用法詳解

發(fā)布時(shí)間:2021-08-17 12:16 來(lái)源: 閱讀:0 作者:佛佛ง 欄目: JavaScript 歡迎投稿:712375056

本文實(shí)例為大家分享了Vue實(shí)現計時(shí)器的具體代碼,供大家參考,具體內容如下

功能簡(jiǎn)介:

1、初始值為0,點(diǎn)擊【加】按鈕,數字自+1;連續點(diǎn)擊【加】,不影響數字+1

2、點(diǎn)擊【?!堪粹o,停止+1

源碼:

<!DOCTYPE html>
<html add="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>Document</title>
  <!-- 1. 導入Vue包 -->
  <script src="./lib/vue-2.4.0.js"></script>
</head>
 
<body>
  <!-- 2. 創(chuàng  )建一個(gè)要控制的區域 -->
  <div id="app">
    <input type="button" value="加" @click="add">
    <input type="button" value="停" @click="stop">
    <h4>{{ count }}</h4>
  </div>
 
  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        count: 0,
        intervalId: null
      },
      methods: {
        add() {
          // 計時(shí)器正在進(jìn)行中,退出函數
          if (this.intervalId != null) { 
            return 
          };
          // 計時(shí)器為空,操作
          this.intervalId = setInterval(() => {
            this.count += 1
          }, 400)
        },
        // 停止定時(shí)器
        stop() { 
          clearInterval(this.intervalId)//清除計時(shí)器
          this.intervalId = null;//設置為null 
        }
      }
    })
  </script>
</body>
 
</html>

之前小編收藏了一個(gè)開(kāi)始計時(shí)的組件,這個(gè)組件可直接引入到項目中使用,謝謝原作者分享。

 <template>
    <div class="timer">
    <div ref="startTimer"></div>
    </div>
    </template>
    <script>
    export default {
    name: 'Timer',
    data () {
    return {
    timer: "",
    content: "",
    hour: 0,
    minutes: 0,
    seconds: 0
    }
    },
    created () {
    this.timer = setInterval(this.startTimer, 1000);
    },
    destroyed () {
    clearInterval(this.timer);
    },
    
    methods: {
    startTimer () {
    this.seconds += 1;
    if (this.seconds >= 60) {
    this.seconds = 0;
    this.minute = this.minute + 1;
    }
    
    if (this.minute >= 60) {
    this.minute = 0;
    this.hour = this.hour + 1;
    }
    this.$refs.startTimer.innerHTML = (this.minutes < 10 ? '0' + this.minutes : this.minutes) + ':' + (this.seconds < 10 ? '0' + this.seconds : this.seconds);
    }
    }
    }
    </script>
    <style>
</style>

以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

久久无码喷吹高潮播放不卡| 影音先锋中文字幕亚洲资源站| 久久天天躁狠狠躁夜夜爽| 中国少妇偷人HD| 肥臀熟女一区二区三区| 国产高清国产精品国产专区|