溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

vue.js如何實現(xiàn)簡單計時器功能

發(fā)布時間:2021-08-06 13:42:29 來源:億速云 閱讀:125 作者:小新 欄目:開發(fā)技術

這篇文章將為大家詳細講解有關vue.js如何實現(xiàn)簡單計時器功能,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

具體內容如下

<!DOCTYPE html>
<html lang="en">
<head>
  <title>抬腿計數(shù)器</title>
  <script src="/static/vue/vue.js"></script>
  <script src="/static/vue/index.js"></script>
  <script src="/static/vue/vue-resource.min.js"></script>
  <link rel="stylesheet" href="/static/vue/index.css" >
</head>
<style type="text/css">
  .el-container {
    margin:100px 30px 30px 30px ;
    height:1800px;
    background-color: #B3C0D1;
  }
  .el-button{
    height:1800px;
    width:100%;
    font-size:300px;
  }
</style>
<body>
  <div id="app">
    <el-container>
      <el-button type="primary" :disabled="!canclick" @click="add">
        {{ num }} <el-divider></el-divider> {{ content }}
      </el-button>
    </el-container>
    <video ref="notify">
      <source src="countdown.m4a" />
    </video>
  </div>
  <script>
    new Vue({
      el: '#app',
      data: function () {
        return {
          num:0,
          canclick:true,
          content:"計數(shù)器",
          count:10
        }
      },
      mounted(){
        this.getnum() //獲取所有選擇項
      },
      methods:{
        getnum:function(){
          this.$http.get('/api/count/count.php').then(function(res){
            this.num=res.data 
          },function(){
            console.log('請求失敗處理')
          });
        },
        add:function(){
          this.canclick=false
          this.$refs.notify.play()
          this.content=this.count+'s后結束'
          let clock=setInterval(()=>{
            this.count--
            this.content=this.count+'s后結束'
            if(this.count==0){
              this.content="計數(shù)器"
              clearInterval(clock)
              this.canclick=true
              this.count=10
            }
          },850);
          this.$http.get('/api/count/add.php?num='+this.num).then(function(res){
            this.num=res.data
          },function(){
            console.log('請求失敗處理')
          });
        }
      }
    })
  </script>
</body>
</html>

效果如下

vue.js如何實現(xiàn)簡單計時器功能

vue.js如何實現(xiàn)簡單計時器功能

關于“vue.js如何實現(xiàn)簡單計時器功能”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI