vue-validate-code
vue-validate-code
[!WARNING]
vue-validate-codegenerates and validates codes entirely in the browser. The SVG renderer exposes its characters as DOM text, and client-side checks can always be bypassed. Use it only as a visual interaction aid—not as CAPTCHA, authentication, or abuse prevention. Security-sensitive flows require a server-generated challenge with server-side validation.
Install
npm i vue-validate-code
yarn add vue-validate-code
pnpm add vue-validate-code
Usage
<script lang="ts" setup>
import { ref, useTemplateRef } from 'vue'
import { ValidateCode } from 'vue-validate-code'
const validateCode = ref('')
const validateCodeRef = useTemplateRef('validateCodeRef')
function handleTriggerValidate() {
if (!validateCode.value) {
return console.log('No validate code value')
}
validateCodeRef.value?.validate(validateCode.value)
}
function handleValidateCallback(isValid: boolean) {
if (isValid) {
console.log('validate success')
} else {
console.log('validate fail')
validateCodeRef.value?.update()
}
}
</script>
<template>
<ValidateCode
@validate="handleValidateCallback"
ref="validateCodeRef"
renderer="svg"
/>
<input
v-model="validateCode"
placeholder="Fill the validate code"
/>
<button
@click="handleTriggerValidate"
type="button"
>
Validate
</button>
</template>
Renderer
ValidateCode supports two built-in renderers:
canvas(default)svg
<ValidateCode renderer="canvas" />
<ValidateCode renderer="svg" />
Docs
Check more examples and APIs in Docs
License
Related Packages
@xunlei/vue-lazy-component
Vue.js 2.0 组件级懒加载方案 Vue.js 2.x component level lazy loading solution
14,137
1,003
google-recaptcha-vue3
A lightweight Vue 3 component library supporting Google reCAPTCHA v2 and v3 inte...
3,291
1
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 0.2.0 | ^3.5.0 | MIT | |
| 0.1.0 | ^3.0.0 | MIT | |
| 0.0.10 | ^3.0.0 | MIT | |
| 0.0.9 | ^3.0.0 | MIT | |
| 0.0.8 | ^3.0.0 | MIT | |
| 0.0.7 | ^3.0.0 | MIT | |
| 0.0.6 | ^3.0.0 | MIT | |
| 0.0.5 | ^3.0.0 | MIT | |
| 0.0.4 | ^3.0.0 | MIT | |
| 0.0.3 | ^3.0.0 | MIT | |
| 0.0.2 | ^3.0.0 | MIT | |
| 0.0.1 | ^3.0.0 | MIT |