首页 > 其他分享 >ElementUI Button定时器

ElementUI Button定时器

时间:2022-11-30 17:23:53浏览次数:30  
标签:60 定时器 ElementUI Button 发送 time message buttonName

今天遇到的问题是在做王老师的作业项目中遇到的,就是我要通过邮箱登录,我把这一部分的功能完善了,但是我发现有一个问题,就是可以一直发,这个显然是不行的,因为不加以限制用户可以随意的发送获取验证码的请求,消耗占用了系统资源不说,还会有很多问题,所以我就在button上加了一个定时器,设置60秒的禁用时间。

具体逻辑

发送成功 进入定时器,进行60秒倒计时。

发送失败 不进入定时器。

其实我个人感觉这个还是有问题的,因为这种它的生命周期很短,刷新页面就没了,但是我现在也只能用到这么多了(不知道存到cookie或session行不行)。

代码示例:

    <el-col :span="8">
    <el-button @click="sendCode"  :disabled="buttonDisabled" class="login-content-code">{{ buttonName}}</el-button>
    </el-col>   
data(){ return{   buttonName : '获取验证码',  //按钮名称 buttonDisabled : false,   //按钮是否禁用
time : 60,           //时间 succ : '',           //是否成功发送,根据这个条件来判断是否进入定时器   } }, methods:{ sendCode(){ request.post("/user/sendCode",this.ruleForm).then(res =>{ if(res.code === '0'){ this.$message({ type : "success", message : "发送成功", }) this.succ = '发送成功' }else { this.$message({ type : "error", message : res.msg }) this.succ = '发送失败' } }) var countDown = setInterval(() => { if (this.time < 1) { this.buttonDisabled = false this.buttonName = '获取验证码' this.time = 60 clearInterval(countDown) } else if(this.time >= 0 && this.succ == '发送成功'){ this.buttonDisabled = true this.buttonName = this.time-- + 's后重发' } }, 1000) }, }

定时器这一部分代码是我copy的,然后根据自己的代码又进行了改动,可以参考一下我的代码。

效果展示

 

标签:60,定时器,ElementUI,Button,发送,time,message,buttonName
From: https://www.cnblogs.com/wjingbo/p/16939122.html

相关文章

  • 定时器:ScheduledExecutorService
    方式二:ScheduledExecutorServiceScheduledExecutorService定时器ScheduledExecutorService是jdk1.5中引入了并发包,目的是为了弥补Timer的缺陷,ScheduledExecutorServic......
  • 定时器:Timer
    定时器定时器是一种控制任务延时调用,或者周期调用的技术。作用:闹钟、定时邮件发送。定时器的实现方式方式一:TimerTimer定时器Timer定时器的特点和存在的问题1、Timer是......
  • 直播平台源代码,el-button自定义图片显示
    直播平台源代码,el-button自定义图片显示1在按钮处自定义icon          <el-button@click="to_devops(scope.row.pr_url)">       ......
  • elementui table 实现单选
    参考:https://www.jb51.net/article/257112.htm<el-tableclass="elTable"ref="processDataTable":row-style="rowStyle"......
  • Vue 引入element后el-button等标签PyCharm不识别
    降低element-ui的版本安装对应的"core-js"版本 [email protected](--save是项目安装,-g是全局安装)npmuninstallelement-ui//安装的同时,将信息......
  • vue引入elementUi后打开页面报错Uncaught TypeError: Cannot read properties of unde
    https://blog.csdn.net/ZouZhaoqian/article/details/125779621?spm=1001.2101.3001.6650.7&utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFro......
  • 项目中elementui时间线的使用~✔✔
    Vue项目项目中经常会遇到事件线的功能Timeline,比如说快递跟踪功能等。element.js时间线的使用,先来看效果图是因为element2.6.0之前的版本不支持时间线组件了。所有下载......
  • HTML基础-表单标签,button按钮,select下拉菜单
    HTML基础-表单标签目标和学习路径1.表单标签1.1input系列标签的基本介绍1.2input系列标签-文本框(拓展)value属性和name属性作用介1.3input系列标签-密码框......
  • Elementui多选下拉框数据回显
    今天在做老年病项目时发现需要用大量的单选框,但是单选框显示比较乱,所以我这次用了多选下拉框。环境:Vue3+ElementUI-Plus首先是基本的多选显示下拉框<el-form-itemlab......
  • 0108-Go-定时器
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/tickers目标使用Go语言的定时器。示例packagemainimport("fmt""time")fu......