CountdownVerify 验证码倒计时 
概述
CountdownVerify 验证码倒计时,一般用于短信验证码发送后展现的倒计时。
# 支持平台
| App-vue | App-Nvue | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 | H5 | PC | 快手小程序 | 钉钉小程序 |
|---|---|---|---|---|---|---|---|---|---|---|
| ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
# 引入
以下介绍两种常用的引入方式。
第一种:在页面中引用、注册
import fuiCountdownVerify from "@/components/firstui/fui-countdown-verify/fui-countdown-verify.vue"
export default {
components:{
fuiCountdownVerify
}
}
1
2
3
4
5
6
2
3
4
5
6
第二种:easycom组件规范
传统vue组件,需要安装、引用、注册,三个步骤后才能使用组件。easycom将其精简为一步。
First UI easycom配置请查看 快速上手。
如果不了解easycom,可先查看 官网文档 (opens new window)。
# 代码演示
部分示例演示,完整使用请参考示例程序以及文档API(以下示例写于.vue页面中)。
基础使用
@send 事件为点击按钮时触发的事件,可在此事件中进行发送验证码操作。
通过 ref 来注册组件引用信息,引用信息将会注册在父组件的$refs对象上。注册完成后,通过 this.$refs.XXX 访问到对应的组件实例,并调用上面的实例方法。
<fui-countdown-verify ref="fui_cdv" @send="sendCode"></fui-countdown-verify>
1
methods: {
sendCode() {
//延时为了效果展示
setTimeout(() => {
//发送短信
//...
//success方法:短信发送成功后将组件改为倒计时状态
this.$refs.fui_cdv && this.$refs.fui_cdv.success()
}, 800)
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
出现错误时重置
通过 ref 来注册组件引用信息,引用信息将会注册在父组件的$refs对象上。注册完成后,通过 this.$refs.XXX 访问到对应的组件实例,并调用上面的实例方法 reset 来重置组件状态。
<fui-countdown-verify ref="fui_cdv" @send="sendCode"></fui-countdown-verify>
1
methods: {
sendCode() {
setTimeout(() => {
this.fui.toast('手机号码格式不正确!')
//重置组件状态
this.$refs.fui_cdv && this.$refs.fui_cdv.reset()
}, 200)
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# Slots
| 插槽名称 | 说明 |
|---|---|
| - | - |
# Props
| 属性名 | 类型 | 说明 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| text | String | 发送验证码前按钮显示的文本 | 发送验证码 | - |
| sending | String | 发送中按钮显示的文本 | 正在发送... | - |
| sent | String | 倒计时显示的文本(文本前会自动拼接时间) | s后重新获取 | - |
| seconds | Number, String | 倒计时总秒数 | 60 | - |
| width | Number, String | 按钮宽度,单位rpx | 192 | - |
| height | Number, String | 按钮高度,单位rpx | 60 | - |
| marginLeft | Number, String | 按钮左侧外边距,单位rpx | 0 | - |
| marginRight | Number, String | 按钮右侧外边距,单位rpx | 0 | - |
| radius | Number, String | 按钮圆角值,单位rpx | 8 | - |
| size | Number, String | 按钮字体大小,单位rpx | 24 | - |
| color | String | 按钮字体颜色 | #465CFF | 非Nvue端默认为空,可通过css变量(--fui-color-primary)来改变颜色值 |
| background | String | 按钮背景颜色 | transparent | - |
| borderColor | String | 按钮边框颜色 | #465CFF | 非Nvue端默认为空,可通过css变量(--fui-color-primary)来改变颜色值 |
| param | Number, String | 自定义参数,事件中回传 | 0 | - |
# Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| @send | 点击按钮时触发 | { param:自定义参数 } |
| @countdown | 倒计时时触发 | { param:自定义参数 seconds:剩余秒数 } |
| @end | 倒计时结束时触发 | { param:自定义参数 } |
# Methods
通过 ref 来注册组件引用信息,引用信息将会注册在父组件的$refs对象上。注册完成后,通过 this.$refs.XXX 访问到对应的组件实例,然后按需调用以下方法。
| 方法名 | 说明 | 传入参数 |
|---|---|---|
| @success | 通知倒计时方法(验证码发送成功后调用) | - |
| @reset | 组件重置方法 | - |