Vcode 验证码

用于展现验证码。

使用指南

在 page.json 中引入组件

  1. {
  2. "navigationBarTitleText": "Vcode",
  3. "usingComponents": {
  4. "wux-vcode": "../../dist/vcode/index"
  5. }
  6. }

示例

  1. <view class="page">
  2. <view class="page__hd">
  3. <view class="page__title">Vcode</view>
  4. <view class="page__desc">验证码</view>
  5. </view>
  6. <view class="page__bd">
  7. <view class="weui-cells__title">默认 & 自定义</view>
  8. <view class="weui-cells weui-cells_after-title">
  9. <view class="weui-cell weui-cell_input weui-cell_vcode">
  10. <view class="weui-cell__hd">
  11. <view class="weui-label">验证码</view>
  12. </view>
  13. <view class="weui-cell__bd">
  14. <input class="weui-input" placeholder="请输入验证码" />
  15. </view>
  16. <view class="weui-cell__ft" style="text-align: left">
  17. <wux-vcode bind:change="onChange" />
  18. </view>
  19. </view>
  20. <view class="weui-cell weui-cell_input weui-cell_vcode">
  21. <view class="weui-cell__hd">
  22. <view class="weui-label">验证码</view>
  23. </view>
  24. <view class="weui-cell__bd">
  25. <input class="weui-input" placeholder="请输入验证码" />
  26. </view>
  27. <view class="weui-cell__ft" style="text-align: left">
  28. <wux-vcode canvas-id="custom-canvas" bg-color="#e6f6ff" font-color="#165189" has-point="{{ false }}" has-line="{{ false }}" bind:change="onChange" />
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  1. Page({
  2. data: {},
  3. onLoad() {},
  4. onChange(e) {
  5. console.log(`验证码:${e.detail.value}`)
  6. },
  7. })

视频演示

Vcode

API

Vcode props

参数 类型 描述 默认值
str string 验证码范围 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
num number 验证码长度 6
width number 画布宽度 120
height number 画布高度 40
bgColor string 画布背景色 -
fontColor string 画布字体颜色 -
hasPoint boolean 是否显示干扰点 true
hasLine boolean 是否显示干扰线 true
bind:change function 点击事件的回调函数 -