您当前的位置: 首页 > 

梁云亮

暂无认证

  • 4浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

vue3+elementplus倒计时效果按钮

梁云亮 发布时间:2021-04-28 09:19:00 ,浏览量:4

效果

在这里插入图片描述

代码实现

    
      
            
            
              {{ checkCodeBtn.text }}
            
      
    



import {reactive, ref} from 'vue'
import {ElMessage} from 'element-plus'
import {isPhone, isEmail} from '@/utils/validate'

export default {
  setup(): any {
    let checkCodeBtn = reactive({
      text: '获取验证码',
      loading: false,
      disabled: false,
      duration: 10,
      timer: null
    })
    // 根据用户名获取验证码
    const getCheckCode = () => {
      // 倒计时期间按钮不能单击
      if (checkCodeBtn.duration !== 10) {
        checkCodeBtn.disabled = true
      }
      // 清除掉定时器
      checkCodeBtn.timer && clearInterval(checkCodeBtn.timer)
      // 开启定时器
      checkCodeBtn.timer = setInterval(() => {
        const tmp = checkCodeBtn.duration--
        checkCodeBtn.text = `${tmp}秒`
        if (tmp             
关注
打赏
1665409997
查看更多评论
0.0432s