add vitepress doc
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# Captcha 验证码
|
||||
|
||||
点击刷新的图形验证码,图片由外部 `request` 回调提供。
|
||||
|
||||
## 基础用法
|
||||
|
||||
:::preview 基础用法 || 演示用验证码由内联 SVG 生成,真实项目对接后端接口
|
||||
|
||||
demo-preview=../demos/captcha/basic.vue
|
||||
|
||||
:::
|
||||
|
||||
## 何时使用
|
||||
|
||||
登录、注册、找回密码等需要人机校验的表单里使用。组件不绑定任何接口,图片与标识全部由外部注入。
|
||||
|
||||
## 对接方式
|
||||
|
||||
`request` 接收宽高并返回 `{ id, data }`,其中 `data` 会直接作为图片地址使用:
|
||||
|
||||
```ts
|
||||
import type { CaptchaRequest, CaptchaResult } from "timi-web";
|
||||
|
||||
const requestCaptcha: CaptchaRequest = async (width, height) => {
|
||||
const result = await api.captcha({ width, height });
|
||||
return { id: result.captchaId, data: result.image };
|
||||
};
|
||||
```
|
||||
|
||||
获取到的 `id` 需要与用户填写的验证码一起提交给后端校验,可通过 `update` 事件或组件暴露的 `captchaId` 取得。
|
||||
|
||||
## 刷新
|
||||
|
||||
点击图片即重新调用 `request`,加载期间按钮处于禁用态。请求失败时抛出 `error` 事件而不是中断渲染。
|
||||
|
||||
## API
|
||||
|
||||
<api-table name="Captcha" />
|
||||
Reference in New Issue
Block a user