1、父组件 home.vue

<template><div><SendTime:type="type":maxCount="count":disabled="disabled"@successChange="sendChange"ref="SendTime"/></div>
</template>
<script>
import SendTime from "../components/sendTime/index.vue";
export default {components: { SendTime },data() {return {type:'phone',count:60,disabled:false};},methods:{sendChange(){console.log('发送验证码成功返回的状态')}}
};
</script>

2、子组件 sendTime.vue

<template><divclass="send_time":class="{send_disabled: disabled }"@click="sendTime"><span class="send_count" v-if="timeCount">{{ timeCount }}s </span>{{ msgTitle }}</div>
</template>
<script>
export default {props: {// 类型type: {type: String,required: true,}, //倒计时数maxCount: {type: Number,default: 60,}, //是否禁用disabled: {type: Boolean,default: false,},},data() {return {isLoading: false,isStart: false,timeCount: 0,};},computed: {msgTitle() {if (this.timeCount) {return "后重新发送";}if (this.isStart) {return "重新发送";}return "获取验证码";},},methods: {sendTime() {if (this.disabled) {return;}if (this.timeCount) {return;}// setTimeout代替调用接口,将后端返回的数据通过$emit传给父组件setTimeout(() => {this.startLoop();this.$emit("successChange");this.verbifyType();}, 1000);},verbifyType() { //给出提示是什么验证码if (this.type === "email") {console.log("邮箱验证码已发送,注意查收");} else {console.log("手机验证码已发送,注意查收");}},// 清除倒计时clearTimer() {if (this.$options.__tmp_timer) {clearTimeout(this.$options.__tmp_timer);this.$options.__tmp_timer = null;}},// 倒计时startLoop() {this.clearTimer();this.timeCount = this.maxCount;if (!this.isStart) {this.isStart = true;}const loopTime = (num) => {if (num === 0) {this.clearTimer();return;}this.$options.__tmp_timer = setTimeout(() => {let _num = num - 1;this.timeCount = _num;loopTime(_num);}, 1000);};loopTime(this.timeCount);},},destroyed() {this.clearTimer();},
};
</script>
<style scoped>
.send_time {font-size: 14px;font-weight: 400;color: #3300be;text-decoration: underline;position: relative;text-align: center;cursor: pointer;
}
.send_count{color: red;
}
.send_disabled {opacity: 0.6;cursor: not-allowed;
}
</style>```

封装60秒倒计时vue组件相关推荐

  1. Vue实现发送短息60秒倒计时

    Vue实现发送短息60秒倒计时 Vue实现注册账号时,发送短信60秒倒计时功能,并进行手机号校验的Demo案例,如果能帮到您,我感到非常荣幸,废话不多说,直接上干货, 首先来一个测试页面,引入Vue. ...

  2. 简单实现vue验证码60秒倒计时功能

    简单实现vue验证码60秒倒计时功能 <span v-if="codeShow" @click="getPhoneCode">点击获取验证码< ...

  3. vue获取手机验证码60秒倒计时,不能点击按钮

    vue获取手机验证码60秒倒计时,不能点击按钮 export const resend = element => {console.log(element)var num = 60var tim ...

  4. vue 微信录音倒计时_Vue实现发送短息60秒倒计时

    原文:https://blog.csdn.net/weixin_43201015/article/details/84405352 Vue实现注册账号时,发送短信60秒倒计时功能,并进行手机号校验的D ...

  5. vue中实现60秒倒计时

    vue中实现60秒倒计时 <span>{{count}} s</span> data中: data(){return{show: true,count: '',timer: n ...

  6. vue+elementui 实现点击验证码出现60秒倒计时

    vue+elementui 实现点击验证码出现60秒倒计时 div部分 <div class="verCode@click="getVerCode":disable ...

  7. vue页面实现短信验证码60秒倒计时

    废话不多说,直接上代码. template <div class='single-wrapper fs14'><div class='single-mb'>短信验证</d ...

  8. 免费获取验证码60秒倒计时

    免费获取验证码60秒倒计时 <!DOCTYPE html> <html> <head> <script src="http://libs.baidu ...

  9. 榛子云短信-微信小程序60秒倒计时插件

    为了帮助开发者更便捷的使用微信小程序的短信验证码功能,特别是初学者更好的使用,榛子云短信特地开发了60秒倒计时插件,效果: 使用方法 1.引入插件countdown.js var CountDown ...

  10. 微信小程序60秒倒计时

    大家可以直接使用插件: https://blog.csdn.net/zuoliangzhu/article/details/90140067 微信小程序发送短信验证码后60秒倒计时功能,效果图: 完整 ...

最新文章

  1. 用window.open时能否通过post方式传输数据?
  2. 线程池 java 新建方式_Java线程池的四种创建方式
  3. 在Mono 2.8上部署ASP.NET MVC 2
  4. ubuntu 10.04 CTS 环境搭建
  5. MediaPlayer控件的初探
  6. ecshop二次开发 给商品添加自定义字段【包含我自己进一步的开发实例详解】
  7. Firemonkey ListView 点击事件
  8. javascript 多线程异步队列
  9. spring中配置ioc中的常用注解
  10. [导入]如何在标题栏上增加按钮
  11. LayaBox1.7.16 TiledMap 销毁的问题,TiledMap销毁后屏幕变灰,不能显示
  12. 网络编程——TCP编程及UDP编程
  13. java根据文件字符换行_java操作txt文本(一):遇到指定字符换行
  14. 有什么能测试安卓硬件的软件吗,手机硬件检测工具有哪些 总有一款适合你
  15. 2015年阿里巴巴校招面试经验汇总
  16. iPhone连接Mac电脑总是断开
  17. 技嘉服务器准系统epyc,技嘉为AMD霄龙处理器推出ATX主板 针对AMD EPYC
  18. ART/Dalvik,JVM/Dalvik 虚拟机的区别
  19. 线程池七个参数的含义
  20. 近期1年来PHP面试题整理

热门文章

  1. DS1302时钟芯片读写操作(基于普中A2开发板)
  2. Python数据结构与算法(17)---归并排序
  3. 度量学习中的马氏距离
  4. win7 虚拟wifi服务器,在win7下建立虚拟wifi
  5. 数据分析--PEG策略(选股)
  6. php 新浪微博登陆,PHP使用新浪微博登入第三方网站实例代码
  7. 6410启动问题排除
  8. python爬虫下载恩智浦智能车竞赛技术报告
  9. oracle修改dbf文件,如何修改Oracle的dbf文件位置
  10. html 空格怎么打,空白空格怎么打?