美文网首页工作总结
vue 项目中引入极限验证

vue 项目中引入极限验证

作者: 轩轩小王子 | 来源:发表于2019-02-16 18:30 被阅读0次

1. public index.html 引入js:

<script src="https://static.geetest.com/static/tools/gt.js"></script>

2.在需要的.vue中的data 中声明相应参数

codeParams:{

          product: 'bind',

          https:false,

          success:'',

          gt:'',

          challenge:'',

          new_captcha:''

      },

3. 获取验证码参数

 getCodeParams(){

            var round = parseInt(Math.random()*10+1);

            this.$get('xxx',{code:round}).then((res)=>{ //这是后台获取极限验证码的接口

                if(res.success==1){

                  this.codeParams.success = res.success

                  this.codeParams.gt = res.gt

                  this.codeParams.challenge = res.challenge

                  this.codeParams.new_captcha = res.new_captcha

                  initGeetest(this.codeParams,this.getCode);

                }

            })

        },

4.获取验证码

getCode(captchaObj){

            let vm = this;

            if(document.getElementById('numberCodes')){

                document.getElementById('numberCodes').addEventListener('click', function ()  {

                    let handleTelBlur = vm.handleTelBlur();

                    if (handleTelBlur) {

                        if(vm.telPhone.indexOf('@') > -1){

                            vm.$get('xxx',{keyWordType:2,email:vm.telPhone}).then((response)=>{

                                if(response.enterpriseStatus == 0){

                                    Toast('邮箱未注册',2);

                                    return false;

                                }else{

                                         captchaObj.verify(); //正常情况

                                }

                            })

                        }

                    }

                });

                captchaObj.onSuccess(function () {

                    if(vm.telPhone.indexOf('@') > -1){

                      vm.$post('xxxx',{email:vm.telPhone,codeType:1}).then((response)=>{

                        })

                    }

                    vm.showGetCodeBtn = false;

                    var timer = setInterval(function(){

                        vm.time -- ;

                        if(vm.time<=0){

                            vm.time = 60;

                            vm.showGetCodeBtn = true;

                            clearInterval(timer);

                            vm.codeMobileValue = "重新发送"

                        }

                    },1000)

                })

            }

        },

5.初始化

created(){

        this.getCodeParams();

    },

相关文章

  • vue 项目中引入极限验证

    1. public index.html 引入js: 2.在需要的.vue中的data 中声明相应参数 3. 获取...

  • vue2.0项目中引入sass、less

    一、vue2.0项目中引入sass预编译 (1)安装依赖 vue项目中想要使用sass,需要安装上node-sas...

  • Vue3+TS+Element-plus浅用

    一、创建项目使用(vue create) 二、项目中引入TS 安装前会验证几个问题,如下: 三、安装Element...

  • vue 验证 引入

    http://www.cnblogs.com/xxwang/p/6104715.html以添加 vue验证为例ve...

  • vue2.0项目中引入echarts

    在vue-cli搭建的项目中该如何引入echarts图表呢? 1.首先npm安装echarts npm insta...

  • vue2.0项目中引入iconfont

    在页面开发过程中,经常会遇到需要引入第三方图标库的需求,iconfont是个非常丰富的第三方图标库,到底vue2....

  • vue项目中引入星空特效

    vue项目中引入星空特效 展示 安装插件 在main.js中引入插件 在项目中使用 参数意义 遇到的问题 引入之后...

  • Vue echarts

    官网奉上ECharts vue项目中可以引入echarts或者vue echarts,大致区别如下: echart...

  • vue项目中引入组件

    最近在重构一个vue项目,恨自己当初第一次学的时候没有写博客。现在翻以前自己做的纸质版笔记,不能看,太混乱。所以趁...

  • vue项目中引入sass

    安装依赖: webpack.base.conf.js文件: vue文件:

网友评论

    本文标题:vue 项目中引入极限验证

    本文链接:https://www.haomeiwen.com/subject/frsieqtx.html