<template>
<div>
<input v-model="phoneNumber" placeholder="请输入手机号码" />
<button @click="startCountdown" :disabled="counting">获取验证码</button>
<span v-show="counting">倒计时: {{ countdown }}s</span>
</div>
</template>
<script setup>
import { ref } from "vue";
const phoneNumber = ref("");
const counting = ref(false);
const countdown = ref(60);
const startCountdown = () => {
counting.value = true;
const interval = setInterval(() => {
if (countdown.value > 0) {
countdown.value--;
} else {
counting.value = false;
countdown.value = 60;
clearInterval(interval);
}
}, 1000);
};
</script>