vue 获取验证码倒计时组件

之前写过一个计时函数,有计算误差,但是验证码的60秒倒计时可以忽略这一点点误差。直接上代码。
在这里插入图片描述
在这里插入图片描述

<template><div class="captcha-row"><input class="captcha-input" placeholder="输入验证码" auto-focus /><div v-if="showtime===null" class="captcha-button" @click="send">获取验证码</div><div v-else class="captcha-button">{{showtime}}</div></div>
</template>
<script>
export default {data() {return {// 计时器,注意需要进行销毁timeCounter: null,// null 则显示按钮 秒数则显示读秒showtime: null}},methods: {// 倒计时显示处理countDownText(s) {this.showtime = `${s}s后重新获取`},// 倒计时 60秒 不需要很精准countDown(times) {const self = this;// 时间间隔 1秒const interval = 1000;let count = 0;self.timeCounter = setTimeout(countDownStart, interval);function countDownStart() {if (self.timeCounter == null) {return false;}count++self.countDownText(times - count + 1);if (count > times) {clearTimeout(self.timeCounter)self.showtime = null;} else {self.timeCounter = setTimeout(countDownStart, interval)}}},send() {this.countDown(60);}},
}
</script>
<style lang="less" scoped>
.captcha-row {display: flex;.captcha-button {background: #048fff;color: white;display: flex;justify-content: center;align-items: center;padding: 4rpx 8rpx;width: 320rpx;border-radius: 4rpx;}
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415742.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【iCore1S 双核心板_FPGA】例程十六:基于SPI的ARM与FPGA通信实验

实验现象&#xff1a; 核心代码&#xff1a; int main(void) {int i,n;char buffer[20];char spi_buffer[20];HAL_Init();system_clock.initialize();led.initialize();usart1.initialize(115200);spi.initialize();usart1.printf("Hello! I am iCore1S!\r\n"); …

记录一个奇葩问题 宝塔 nginx: [warn] conflicting server

宝塔面板里面运行很久的nginx&#xff0c;好久没有重启&#xff0c;这次一重启&#xff0c;报错了。 解决方法&#xff0c;去/www/server/panel/vhost/nginx目录下&#xff0c;把相关的历史记录给删掉&#xff0c;再重启&#xff0c;就没有问题了

小程序设置页面背景颜色

首先&#xff0c;我使用的是mpvue开发。样式使用的less&#xff0c;并且全局会定义一套主题。 primary-color : #ff8730; second-color : #F48B4A; background-color :#F3F3F3; second-text-color :#787878;.flex-center-row {display: flex;flex-d…

Arcgis10安装说明

1、 先安装dotnet framework 3.5 ,必须要装这个才能运行安装程序。 2、 接着安装Arcgis Desktop &#xff0c;只需下一步&#xff0c;下一步执行就好了。完成后&#xff0c;停掉服务。 3、 安装LicenseManager &#xff0c;下一步执行就可以。 4、 接着来破解&…

前端学习(2606):vue简单叙述

第一步 引入 第二步new Vue 第三步 data绑定数据

wux-button 样式扩展 增加shape属性

1、原来的写法和界面图如下 <wux-button block type"orange">拍照确认</wux-button>2、现在的写法只需要增加一个shape"round"参数&#xff0c;可以实现按钮边框为半圆 <wux-button block type"orange" shape"round"&g…

前端框架Bootstrap简单介绍

下载&#xff1a; 解压之后&#xff1a; 把这些文件拷贝到项目中 页面使用时 只需要引入&#xff1a; 然后我们就可以参考官网来设计需要的前端页面了 设计一个按钮&#xff1a;button 只需要标明css样式中使用的类 下面就是现实效果&#xff1a; 转载于:https://www.cnblo…

vue学习中遇到的错误 Duplicate keys detected: ‘[object Object]‘. This may cause an update error.

前端入门自学&#xff0c;说错的请大神指点。 Avoid using non-primitive value as key, use string/number value instead. Duplicate keys detected: ‘[object Object]’. This may cause an update error.运行后出现这些警告&#xff0c;意思是检测到重复的键值。 把:key里…

工作113:添加echart折线图

<template><div><el-card><div slot"header" class"clearfix"><span>订单信息</span></div><!--样式控制全部 已经退回 待审核--><el-row><el-radio-group v-model"query.status" siz…

Android 城市选择,热门城市,全部城市(美团、滴滴、淘宝)

demo链接&#xff1a;https://download.csdn.net/download/meixi_android/10819638 实现效果&#xff1a; 实现方法&#xff1a;非常简洁快速&#xff0c;三步集成实现地区选择器 1、导入city.module module导入方法&#xff1a;https://blog.csdn.net/meixi_android/articl…

汽车列表 车型选择 源码备忘

因为版权问题&#xff0c;选汽车的时候不能显示汽车自己真实的图片&#xff0c;下面我需要改成列表形式&#xff0c;下面记录一下代码 1、实现效果 2、源码 <div class"car-brand-list"><div v-for"(brand,index) in brandList" :key"inde…