首页 > 其他分享 >vue点击按钮后倒计时

vue点击按钮后倒计时

时间:2023-02-26 00:56:02浏览次数:37  
标签:count vue 验证码 timer 倒计时 按钮

vue代码

<template>
  <div>
    <!-- 点击按钮后倒计时 -->
    <el-button @click="signUp_asd" type="success" :disabled="!show">
      获取验证码
      <span v-show="!show" class="count">({{count}}s)</span>
    </el-button>
  </div>
</template>

<script>
const TIME_COUNT = 30; //更改倒计时时间
export default {
  mounted() {},
  name: "MyApp",
  data() {
    return {
      //60秒验证码发送
      show: true, // 初始启用按钮
      count: "", // 初始化次数
      timer: null,
      form: {
        code: ""
      }
    };
  },
  methods: {
    signUp_asd() {
      //60秒验证码
      if (!this.timer) {
        this.count = TIME_COUNT;
        this.show = false;
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= TIME_COUNT) {
            this.count--;
          } else {
            this.show = true;
            clearInterval(this.timer); // 清除定时器
            this.timer = null;
          }
        }, 1000);
      }
    }
  }
};
</script>

 
<style scoped>
</style>

 效果

 

标签:count,vue,验证码,timer,倒计时,按钮
From: https://www.cnblogs.com/xbinbin/p/17155799.html

相关文章

  • vue中获取网址上的参数
    vue代码<template><div><h4>http://localhost:8080/#/test?levels=level1-1</h4><h4>获取levels1-1</h4>levels={{levels}}</div></template><......
  • vue遍历数据
    vue代码<template><divclass="index"><!--遍历--><divv-for="(item,index)incatalogue":key="index"><!--页面跳转--><!--<route......
  • vue图片热区map-area定位(适应屏幕)
    vue代码<template><div>{{screenWidth}}{{screeHeight}}<divv-for="(item,index)inbook":key="index"><!--当从后台获取数据的时候可以进行......
  • vue获取屏幕长宽
    vue代码<template><div>寬:{{screenWidth}}高:{{screeHeight}}</div></template><script>exportdefault{data(){return{screenWidth:1000,//......
  • odoo 给form表单视图内联列表添加按钮
    实践环境Odoo14.0-20221212(CommunityEdition)代码实现模块文件组织结构说明:为了更好的表达本文主题,一些和主题无关的文件、代码已略去odoo14\custom\estate│_......
  • vue前端调用百度定位API进行定位
    首先进入 百度地图API 申请百度定位使用的域名必须填写,否则无法定位vue前端代码<template><div>城市:{{city}}</div></template><script>importaxiosfrom......
  • 【vue3】vue3+ts+vite项目创建
    1、npminitvite@lastest 2、项目目录结构  3、npminstall(i) 安装依赖(是根据package.json中devDependencies的依赖安装的)启动命令 dev  打包命令build预......
  • Vue3 + Vite +TS 项目问题总结
    最近做的几个Vue项目基本都收尾了,总结一下在项目中遇到的问题,希望能帮助遇到同样问题的小伙伴项目情况:我做的项目都是Vue3.2(setup语法)+Vite+TS,一个H5项目,一个PC前......
  • 【vue3】实现全屏功能
    前言全屏效果:实现安装依赖包npmi@vueuse/core调用import{useFullscreen}from'@vueuse/core'useFullscreen的使用文档:https://vueuse.org/core/useFull......
  • Vue3学习笔记(1)
    安装//使用yarn构建//安装yarn需要管理员权限sudonpmiyarn-gyarncreatevitecd..yarnyarndev目录结构见名知义四种......