0
点赞
收藏
分享

微信扫一扫

使用svg-captcha获取验证码

奔跑的酆 2022-04-05 阅读 51
前端

先放上svg-captcha的npm地址 svg-captcha

介绍使用方法:
1.样式布局

    <div class="flex">
      <span v-html="codeHtml" />
      <el-button type="text" @click="getCaptchaDetail">
      {{ $t('看不清,换一张') }}
      </el-button>
    </div>
  1. js (放个简单的代码,主要看svgCaptcha.create的使用)
const svgCaptcha = require('svg-captcha')
getCaptchaDetail = ()=> {
 let captcha = svgCaptcha.create({
      height: 36, // 下面都是配置项,详细可看官网
      fontSize: 40,
      color: false,
      ignoreChars: '0oO1iIl',
      noise: 1
    })
this.exportCode = captcha.text // 记录验证码的值
this.codeHtml = captcha.data // 获取验证码的 html
}

3.结果图展示
在这里插入图片描述

举报

相关推荐

0 条评论