Skip to content

SlideVerify 滑动验证

滑动验证组件,用于人机验证场景。

基本用法

html
<wd-slide-verify @success="handleSuccess" @fail="handleFail" />
typescript
const toast = useToast()

function handleSuccess() {
  toast.success('验证成功')
}

function handleFail() {
  toast.error('验证失败,请重试')
}

自定义文案

通过 textsuccess-text 属性自定义提示文字。

html
<wd-slide-verify text="请拖动滑块" success-text="验证成功" />

自定义尺寸

通过 widthheight 属性自定义滑动条的宽度和高度。 通过 icon-sizesuccess-icon-size 属性设置对应图标大小。

html
<wd-slide-verify :width="250" :height="50" icon-size="60rpx" success-icon-size="30rpx" />

自定义颜色

通过 background-coloractive-background-color 属性自定义颜色。

html
<wd-slide-verify background-color="#E8F4FF" active-background-color="#4D94FF" />

自定义图标

通过 iconsuccess-icon 属性自定义图标,icon-size 属性设置图标大小。

html
<wd-slide-verify icon="arrow-right" success-icon="success" :icon-size="24" />

自定义容错范围

通过 tolerance 属性设置容错范围(单位:px),默认为 10px。

html
<wd-slide-verify :tolerance="20" />

禁用状态

设置 disabled 属性禁用滑动验证。

html
<wd-slide-verify disabled />

重置方法

通过 ref 获取组件实例,调用 reset 方法重置验证状态。

html
<wd-slide-verify ref="slideVerifyRef" />
<wd-button @click="handleReset">重置</wd-button>
typescript
import { ref } from 'vue'
import type { SlideVerifyInstance } from '@/uni_modules/wot-design-uni/components/wd-slide-verify/type'

const slideVerifyRef = ref<SlideVerifyInstance>()

function handleReset() {
  slideVerifyRef.value?.reset()
}

插槽

支持通过插槽自定义内容。

html
<wd-slide-verify>
  <template #text>
    <text>向右滑动完成验证</text>
  </template>
  <template #success-text>
    <text>验证通过</text>
  </template>
  <template #icon>
    <view>ICON</view>
  </template>
  <template #success-icon>
    <view style="color: red">OK</view>
  </template>
</wd-slide-verify>

Attributes

参数说明类型可选值默认值最低版本
width滑动条宽度(单位:px)number / string-3001.14.0
height滑块高度(单位:px)number / string-401.14.0
tolerance容错范围(单位:px),距离终点多少距离内视为验证通过number / string-101.14.0
text提示文字string-向右滑动验证1.14.0
success-text验证成功提示文字string-验证通过1.14.0
disabled是否禁用boolean-false1.14.0
background-color背景颜色string-#F5F7FA1.14.0
active-background-color激活时的背景颜色string-#49C75F1.14.0
icon滑块图标名称string-a-chevron-rightdouble1.14.0
success-icon成功图标名称string-check1.14.0
icon-size图标大小(单位:px)number / string-201.14.0
success-icon-size成功图标大小(单位:px)number / string-121.14.0

Events

事件名称说明参数最低版本
success验证成功时触发-1.14.0
fail验证失败时触发-1.14.0

Methods

通过 ref 可以获取到组件实例,调用组件提供的方法:

方法名说明参数最低版本
reset重置验证组件到初始状态-1.14.0

Slots API

插槽名称说明最低版本
text自定义提示文字内容1.14.0
success-text自定义验证成功提示文字内容1.14.0
icon自定义滑块图标1.14.0
success-icon自定义成功图标1.14.0

外部样式类

类名说明最低版本
custom-class根节点样式1.14.0
custom-style根节点样式1.14.0

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.