手机号倒计时模板

<template>
  <view class="wai">
    <view class="bd">绑定手机号</view>
    <view class="wz">为防止账号丢失以及方便找回,建议你绑定手机号码后在使用</view>
    <view class="souji">
      <view class="sera">手机号</view>
      <input v-model="mobile" class="inputo" placeholder="请输入手机号" type="text" />
    </view>
    <view class="yanz">
      <view class="yzm">验证码</view>
      <input v-model="sms" style="flex: 1" placeholder="请输入验证码" type="text" />
      <view class="hq" :disabled="isCounting" @click="getVerificationCode">{{ isCounting ? countdownText : '获取验证码' }}</view>
    </view>
    <view class="btn">完成</view>
  </view>
</template>

<script setup>
import { ref, onMounted, onUnmounted, computed } from 'vue';
import { uniFetch } from '@/conmit/uniFetch.js';
const sms = ref(''); //获取验证码的值
const mobile = ref(''); //获取手机号
const isCounting = ref(false);
const countdown = ref(60); //倒计时
let timer = null;
// 计算倒计时的文本
const countdownText = computed(() => {
  if (isCounting.value) {
    return `${countdown.value}s重新获取`;
  }
});
const getVerificationCode = () => {
  if (isCounting.value) return; // 如果已经在倒计时,则不执行
  isCounting.value = true; // 开始倒计时
  startCountdown();
};

const startCountdown = () => {
  timer = setInterval(() => {
    if (countdown.value > 0) {
      //如果秒数大于零就--
      countdown.value--;
    } else {
      //如果不大于零就移除定时器,其他数据复原
      clearInterval(timer);
      isCounting.value = false;
      countdown.value = 60;
    }
  }, 1000);
};
// 移除定时器
const resetCountdown = () => {
  clearInterval(timer);
  isCounting.value = false;
  countdown.value = 60;
};

onMounted(() => {
  // 组件挂载时的逻辑(如果有的话)
});

onUnmounted(() => {
  // 组件卸载时清除定时器
  resetCountdown();
});
</script>

<style lang="scss" scoped>
.wai {
  .btn {
    height: 76.92rpx;
    color: #fff;
    text-align: center;
    line-height: 76.92rpx;
    background: #ed1017;
    // background-color: #ed1017;
    border-radius: 38rpx;
  }
  .yanz {
    .yzm {
      color: #666666;
      margin-right: 46.15rpx;
    }
    .hq {
      color: #ed1017;
      // font-size: 26.92rpx;
    }
    display: flex;
    // flex-wrap: nowrap;
    height: 85rpx;
    background-color: #f7f7f7;
    border-radius: 10rpx;
    margin-top: 23.08rpx;
    padding: 23.08rpx;
    margin-bottom: 107.69rpx;
  }
  .souji {
    display: flex;
    height: 84.62rpx;
    background-color: #f7f7f7;
    border-radius: 10rpx;
    padding: 23.08rpx;
    .sera {
      margin-right: 46.15rpx;
      color: #666666;
    }
    .inputo {
      flex: 1;
    }
  }
  .wz {
    margin-bottom: 61.54rpx;
    font-weight: 400;
    font-size: 27rpx;
    color: #666666;
  }
  .bd {
    margin-top: 67.31rpx;
    margin-bottom: 15.38rpx;
    font-size: 38rpx;
    color: #000000;
    font-weight: 500;
  }
  padding: 0 46.15rpx;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值