前端(vue)实现图形(拼图等)验证码

一、第一种

  • vue移动端(PC端)图形验证码
  • vue2-verify
  • 前往地址
    常规验证码picture 常规的验证码由数字和字母构成,用户输入不区分大小写,可变形成汉字验证。
    运算验证码compute 运算验证码主要通过给出数字的加减乘运算,填写运算结果进行验证。
    滑动验证码slide 通过简单的滑动即可完成验证,应用与移动端体验很好。
    拼图验证码puzzle 拼图。
    选字验证码pick 通过按顺序点选图中的汉字完成验证,ie浏览器要求9或以上。
<Verify  @success="onSuccess" @error="onFail" :type="5" :imgSize="imgSize" :imgUrl="imgUrl" :imgName="imgName" :mode="pop" :barSize="barSize" :showButton="showButton"></Verify>  

------------------------script------------------------------
import Verify from 'vue2-verify';
 components: {
      Verify
    },
------------------------options------------------------------------
ready	验证码初始化成功的回调函数。
success	验证码匹配成功后的回调函数。如要重新初始化:success:function(obj){obj.refresh();}。
error	验证码匹配失败后的回调函数。


**其他配置项去上面地址查看**

二、第二种(vue)

  • slide-verify(一款拼图验证码)
  • 图片建议传、不传的话默认图片加载非常慢
  • github文档地址: https://github.com/monoplasty/vue-monoplasty-slide-verify
  • gitee镜像地址:https://gitee.com/monoplasty/vue-monoplasty-slide-verify
//demo
// main.js(全局引入也可以局部引入)
import Vue from 'vue';
import SlideVerify from 'vue-monoplasty-slide-verify';
Vue.use(SlideVerify);
// template
<slide-verify 
    ref="slideblock"
    @again="onAgain"
    @fulfilled="onFulfilled"
    @success="onSuccess"
    @fail="onFail"
    @refresh="onRefresh"
    :accuracy="accuracy"
    :slider-text="text"
></slide-verify>
<div>{{msg}}</div>

<button @click="handleClick">在父组件可以点我刷新哦</button>
// script
export default {
   name: 'App',
    data(){
        return {
            msg: '',
            text: '向右滑',
            // 精确度小,可允许的误差范围小;为1时,则表示滑块要与凹槽完全重叠,才能验证成功。默认值为5
            accuracy: 1,
        }
    },
    methods: {
        onSuccess(times){
           console.log('验证通过,耗时 +' times + '毫秒');
            this.msg = 'login success, 耗时${(times / 1000).toFixed(1)}s'
        },
        onFail(){
            console.log('验证不通过');
            this.msg = ''
        },
        onRefresh(){
            console.log('点击了刷新小图标');
            this.msg = ''
        },
        onFulfilled() {
            console.log('刷新成功啦!');
        },
        onAgain() {
            console.log('检测到非人为操作的哦!');
            this.msg = 'try again';
            // 刷新
            this.$refs.slideblock.reset();
        },
        handleClick() {
        	// 父组件直接可以调用刷新方法
            this.$refs.slideblock.reset();
        },
    }
}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue可以通过使用第三方库来实现图形验证码登录。下面我会给你一个基本的实现步骤: 1. 首先,需要安装一个适用于Vue图形验证码库,比如`vue-verify-code`。通过运行以下命令进行安装: ``` npm install vue-verify-code ``` 2. 在你的Vue组件中,导入所需的库,并使用它来生成图形验证码。在模板中添加一个`<verify-code>`标签来展示图形验证码,如下所示: ```vue <template> <div> <verify-code ref="verifyCode"></verify-code> <button @click="refreshCode">刷新验证码</button> <input type="text" v-model="inputCode" placeholder="请输入验证码"> <button @click="verifyCode">验证</button> </div> </template> <script> import VerifyCode from 'vue-verify-code'; export default { components: { VerifyCode }, data() { return { inputCode: '' }; }, methods: { refreshCode() { this.$refs.verifyCode.refresh(); }, verifyCode() { const result = this.$refs.verifyCode.verify(this.inputCode); if (result) { // 验证通过,执行登录操作 // ... } else { // 验证失败,提示用户重新输入 // ... } } } } </script> ``` 3. 上述代码中,通过`this.$refs.verifyCode.refresh()`方法可以刷新验证码,而`this.$refs.verifyCode.verify(this.inputCode)`方法可以用于验证用户输入的验证码是否正确。根据验证结果,你可以执行相应的操作。 请注意,上述代码只是一个简单的示例,你需要根据具体的需求进行适当的修改和扩展。另外,确保你已经在项目中导入了相关的CSS文件,以使图形验证码正常显示。 希望以上内容对你有所帮助!如有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值