验证码插件的使用

验证码插件captcha-mini的使用

  1. 使用yarn add captcha-mini命令安装插件

yarn add captcha-mini

  1. js中引入验证码插件
// 引入验证码插件
let Captcha = require('captcha-mini')
  1. 验证码实例化
 // 1: 验证码实例化
    let captcha1 = new Captcha({
        lineWidth: 1,   //线条宽度
        lineNum: 3,       //线条数量
        dotR: 2,          //点的半径
        dotNum: 15,       //点的数量
        preGroundColor: [60, 80],    //前景色区间
        backGroundColor: [150, 250], //背景色区间
        fontSize: 100,           //字体大小
        fontFamily: ['Georgia', '微软雅黑', 'Helvetica', 'Arial'],  //字体类型
        fontStyle: 'stroke',      //字体绘制方法,有fill和stroke
        content: 'abcdefghijklmnopqrstuvwxyz',  //验证码内容
        length: 4    //验证码长度
    });
  1. 找一变量在外部储存验证码
let code = ''//储存验证码; 
  1. 放入这一句, 动态获取验证码
// 3: 切换验证码会返回新的验证码
    captcha1.draw(document.querySelector('#captcha1'), r => {
        code = r //实时更新验证码
    });
posted @ 2023-05-10 10:01  Lyc1cccccccc  阅读(104)  评论(0)    收藏  举报