vue封装图片滑块验证+读秒组件

vue封装图片滑块验证+读秒组件
摘要由CSDN通过智能技术生成

我们在项目开发过程中经常会遇到用户发送验证码后唤起图片滑块验证,验证成功后触发发送验证码事件(不处理发送验证码逻辑父组件去监听)进而读秒等流程,特此封装了该组件。

 

 

1、html部分

<template>
    <div>
        <div v-if="countDownNum < 1" @click="_sendCode" slot="suffix" class="modifyColor"
             :class=" _disabled ? 'disabled' : 'hover7'">
            发送验证码
        </div>
        <div v-else class="mt6 modifyColor">
            {
  { countDownNum }}S
        </div>
        <div :id="cacheKey"></div>
    </div>
</template>

2、css部分

.modifyColor {
    color: #4C70DF;
    padding-right:15px;
}

.mt6{
    margin-top: 6px;
}

3、js部分

(1)将以下内容放在public文件夹中取名为yidun.js

(function (global, factory) {
    'use strict'
    if (typeof module === 'object' && typeof module.exports === 'object') {
        module.exports = global.document ? factory(global) : function (w) {
            if (!w.document) {
                throw new Error('initNECaptchaWithFallback requires a window with a document')
            }
            return factory(w)
        }
    } else if (typeof define === 'function' && define.amd) {
        define('initNECaptchaWithFallback', [], function () {
            return factory(global)
        })
    } else {
        global.initNECaptchaWithFallback = factory(global)
    }
}(typeof window !== 'undefined' ? window : this, function (window) {
    'use strict'
    var errorCallbackCount = 0
    // 常量
    var DEFAULT_VALIDATE = 'QjGAuvoHrcpuxlbw7cp4WnIbbjzG4rtSlpc7EDovNHQS._ujzPZpeCInSxIT4WunuDDh8dRZYF2GbBGWyHlC6q5uEi9x-TXT9j7J705vSsBXyTar7aqFYyUltKYJ7f4Y2TXm_1Mn6HFkb4M7URQ_rWtpxQ5D6hCgNJYC0HpRE7.2sttqYKLoi7yP1KHzK-PptdHHkVwb77cwS2EJW7Mj_PsOtnPBubTmTZLpnRECJR99dWTVC11xYG0sx8dJNLUxUFxEyzTfX4nSmQz_T5sXATRKHtVAz7nmV0De5unmflfAlUwMGKlCT1khBtewlgN5nHvyxeD8Z1_fPVzi9oznl-sbegj6lKfCWezmLcwft8.4yaVh6SlzXJq-FnSK.euq9OBd5jYc82ge2_hEca1fGU--SkPRzgwkzew4O4qjdS2utdPwFONnhKAIMJRPUmCV4lPHG1OeRDvyNV8sCnuFMw7leasxIhPoycl4pm5bNy70Z1laozEGJgItVNr3' // 默认validate
    var FALLBACK_LANG = {
        'zh-CN': '前方拥堵,已自动跳过验证',
        'en': 'captcha error,Verified automatically'
    }
    var CACHE_MIN = 1000 * 60 // 缓存时长单位,1分钟
    var REQUEST_SCRIPT_ERROR = 502
    var RESOURCE_CACHE = {}
    // 工具函数
    function loadScript(src, cb) {
        var head = document.head || document.getElementsByTagName('head')[0]
        var script = document.createElement('script')

        cb = cb || function () {}

        script.type = 'text/javascript'
        script.charset = 'utf8'
        script.async = true
        script.src = src

        if (!('onload' in script)) {
            script.onreadystatechange = function () {
                if (this.readyState !== 'complete' && this.readyState !== 'loaded') return
                this.onreadystatechange = null
                cb(null, script) // there is no way to catch loading errors in IE8
            }
        }

        script.onload = function () {
            this.onerror = this.onload = null
            cb(null, script)
        }
        script.onerror = function () {
            // because even IE9 works not like others
            this.on
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值