Skip to content

SliderCaptchaModal 滑块验证码

滑块拼图验证码模态框,基于 vue3-slide-verify 实现拖拽验证。

使用方式

vue
<template>
  <n-button @click="showCaptcha = true">验证</n-button>
  <SliderCaptchaModal
    v-model:show="showCaptcha"
    :images="captchaImages"
    @success="onVerified"
    @fail="onFailed"
  />
</template>

<script setup>
import { ref } from 'vue'
import SliderCaptchaModal from '@/components/SliderCaptchaModal.vue'

const showCaptcha = ref(false)
const captchaImages = ref(['/captcha-bg-1.jpg', '/captcha-bg-2.jpg'])

function onVerified() {
  console.log('验证通过')
}

function onFailed() {
  console.log('验证失败')
}
</script>

Props

属性类型默认值说明
showBooleanfalse控制显示/隐藏(v-model)
imagesArray[]拼图背景图片列表

Events

事件参数说明
update:show(value: boolean)显示状态变更
success-验证通过
fail-验证失败
refresh-刷新验证码

暴露方法

方法说明
reset()重置验证码
handleClose()关闭弹窗

行为

  • 验证成功后 800ms 自动关闭
  • 验证失败时显示错误提示,然后重置

依赖

  • vue3-slide-verify
  • naive-ui(NModal)