验证码倒计时
验证码倒计时函数。
提示
该组件不提供界面,实际是一个组合式函数,之所以放到组件中,是因为经常用到。
使用示例
vue
<template>
<pure-button
:text="tips"
:disabled="isCountdown"
theme="primary"
block
@onClick="start"
></pure-button>
</template>
<script setup>
import { ref } from "vue";
// 引入函数
import { usePureCodeCountdown } from "@/uni_modules/pure-utils";
// 使用函数
// seconds: 剩余秒数
// isCountdown: 是否正在倒计时
// tips: 提示文本
// start: 开始函数
// clear: 清除函数
const { seconds, isCountdown, tips, start, clear } = usePureCodeCountdown({
// 唯一key,设置后可以在刷新页面后继续倒计时
key: "login",
// 倒计时总秒数
seconds: 60,
// 倒计时结束后的回调函数
end: null,
// 倒计时变化后的回调函数,每秒触发一次
change: null,
// 默认提示文本
defaultText: "发送验证码",
// 倒计时中的提示文本,其中 "{seconds}" 为秒数占位符
countdownText: "{seconds}S",
// 倒计时结束后的提示文本
endText: "重新发送"
});
</script>