behavior-captcha

Vue3 行为验证码
1,557
Install
npm install behavior-captcha
Latest Version:2.0.6
Vue:3
License:MIT
Last Updated:Oct 12, 2026
Links: npm
Maintainer: tanglibin

behavior-captcha

基于 Vue3 的行为验证码组件(增强版多类型),兼容 H5 / PC,可在 uni-app 的 App-Vue / H5 中使用。

后台可对接开源增强版 tianai-captcha。

支持类型
type 说明
SLIDER 滑块拼图
SLIDER2 滑块拼图(旋转缺口)
CURVE2 曲线匹配(椭圆)
CURVE3 曲线匹配(双贝塞尔)
GESTURE 手势沿路径滑动
JIGSAW 乱序拼图交换
IMAGE_CLICK 图标点选

未知 type 会自动重拉最多 3 次;仍失败则展示刷新入口。

安装
npm i -S behavior-captcha
注册

全局:

import BehaviorCaptchaPlugin from 'behavior-captcha'
import 'behavior-captcha/lib/style.css'
app.use(BehaviorCaptchaPlugin)

局部:

import { BehaviorCaptcha } from 'behavior-captcha'
import 'behavior-captcha/lib/style.css'
属性
属性 类型 默认 说明
modelValue / v-model Boolean false 是否显示
locale String 'en' en / zh / vi / id
generateFun Function 必填 生成钩子,resolve 解包后的验证码对象
checkFun Function 必填 校验钩子,入参 { id, data };成功 resolve 业务 data,失败 resolve null

v2 已移除 textData,文案由 locale 内置词条控制。

generateFun

接口若返回 { code, data },请先解包 data:

generateFun() {
  return fetch('/api/gen?type=SLIDER')
    .then((r) => r.json())
    .then((json) => {
      if (json.code !== 200) throw new Error(json.msg)
      return json.data // 含 id / type / backgroundImage ...
    })
}
checkFun

组件内部已对轨迹做 enc 加密,业务侧只需转发:

checkFun(param) {
  // param = { id, data: '<enc string>' }
  return fetch('/api/check', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(param)
  })
    .then((r) => r.json())
    .then((json) => (json.code === 200 ? json.data : null))
}
事件
事件 说明
success 校验成功,参数为 checkFun resolve 的值
update:modelValue 关闭/成功后同步显示状态
本地 Demo(仅仓库内,不发布到 npm)
npm install
npm run dev        # 本地联调 Demo
npm run build      # 产出 lib/

Demo 入口为 index.html / src/example / vite.config.js,已通过 package.json 的 files 白名单与 .npmignore 排除,不会打进 npm 包。包内仅含 lib/、src/package/、README.md。

更新日志
  • 2.0.1 默认入口按 isUni() 分流;排除业务假 uni polyfill(无 createSelectorQuery),避免 H5 误走 uni 组件
  • 2.0.0 增强版多类型重构;内置 enc;locale 多语言(默认 en);深色 UI;移除 textData
  • 1.0.x 初版滑块

Related Packages

vue-slider-captcha

使用方法

739
vue-concise-slider

vue-slider,A simple sliding component,has easy configuration,support self-adapti...

125,004
vue-swipe

A touch slider for vue.js.

22,780 909
vue-monoplasty-slide-verify

vue slide verify

21,200 761
@johnnyguan/vue-captcha-code

vue captcha code

2,470 0

Version History

Version Released Vue License
2.0.6 ^3.0.0 MIT
2.0.5 ^3.0.0 MIT
2.0.4 ^3.0.0 MIT
2.0.3 ^3.0.0 MIT
2.0.2 ^3.0.0 MIT