iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >vue.js实现简单计时器功能
  • 542
分享到

vue.js实现简单计时器功能

2024-04-02 19:04:59 542人浏览 独家记忆
摘要

本文实例为大家分享了vue.js实现简单计时器功能的具体代码,供大家参考,具体内容如下 <!DOCTYPE html> <html lang="en">

本文实例为大家分享了vue.js实现简单计时器功能的具体代码,供大家参考,具体内容如下


<!DOCTYPE html>
<html lang="en">
<head>
  <title>抬腿计数器</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:"计数器",
          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="计数器"
              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>

效果如下

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: vue.js实现简单计时器功能

本文链接: https://www.lsjlt.com/news/132000.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作