推荐一款前端滑动验证码插件(Vue、uniapp)

uniapp版本:滑块拼图验证码,有后端,简单几步即可实现,小程序、h5都可以用 - DCloud 插件市场

Vue版本及cdn版本可以查阅文档: 行为验证 | Poster 文档

示例代码:

javascript 复制代码
<template>
  <view id="app">
    <button @click="open">验证</button>
    <slider-captcha 
      v-model="visible"
      :options="options"
      :loading="loading"
      @check="check"
      @close="close"
      @refresh="getSliderOptions"
      @error="getSliderOptions"
    >
            <!-- vue2 -->
      <view slot="title">自定义标题-安全验证</view>
      <view slot="successText">自定义成功提示-登录中</view>
      <view slot="errorText">自定义错误提示-是不是太难了换一个</view>
      <view slot="tips">自定义提示拖动下方滑块完成拼图</view>
            <!-- <view slot="question">自定义提示</view> -->
            <!-- vue2 -->

            <!-- vue3 -->
            <template #title>自定义标题-安全验证</template>
            <template #successText>自定义成功提示-登录中</template>
            <template #errorText>自定义错误提示-是不是太难了换一个</template>
            <template #tips>自定义提示拖动下方滑块完成拼图</template>
            <!-- <template #question>自定义提示</template> -->
            <!-- vue3 -->
    </slider-captcha> 
  </view>
</template>

<script>
import SliderCaptcha from '@/components/kkokk-slider-captcha.vue'
export default {
  components:{SliderCaptcha},
  data(){
    return {
      visible: false,
      loading: false,
      options: {}
    }
  },
  methods: {
    // 打开触发
    open() {
      this.visible = true
      this.getSliderOptions()
    },
    // 验证
    check(sliderKey, sliderX, done, error)
    {
      // 这里是验证是否成功的接口
            this.loading = true
            uni.request({
                url: 'http://192.168.10.76:8111/', 
                header: {
                    // 'Content-Type': 'application/x-www-form-urlencoded'
                     'Content-Type': 'application/json' //自定义请求头信息
                },
                data:{
                    sliderKey:sliderKey,
                    sliderX:sliderX
                },
                method:'POST',//请求方式,必须为大写
                success: (res) => {
                    this.loading = false
                    done()
                },
                fail: () => {
                    this.loading = false
                    error()
                }
            })
    },
    // 关闭触发
    close() {

    },
    // 获取滑块验证参数
    getSliderOptions()
    {
      this.loading = true
            uni.request({
                url: 'http://192.168.10.76:8111/', 
                header: {
                    // 'Content-Type': 'application/x-www-form-urlencoded'
                     'Content-Type': 'application/json' //自定义请求头信息
                },
                method:'GET',//请求方式,必须为大写
                success: (res) => {
                    const {img, key, y} = res.data
                    this.options = {
                        sliderImg: img,
                        sliderKey: key,
                        sliderY: y
                    }
                    this.loading = false
                }
            })
    }
  }
}
</script>

使用效果:

唯一不足的是:依赖的后端环境是php

相关推荐
烟雨落金城2 分钟前
初识Electron,谈谈感悟
前端
jeff渣渣富3 分钟前
Taro 小程序构建自动化:手写插件实现图片自动上传 OSS 并智能缓存
前端·webpack
恋猫de小郭19 分钟前
谷歌 Genkit Dart 正式发布:现在可以使用 Dart 和 Flutter 构建全栈 AI 应用
android·前端·flutter
进击的尘埃2 小时前
策略模式和状态模式到底啥区别?拿审批流表单说个明白
javascript
vim怎么退出2 小时前
谷歌性能优化知识点总结
前端
专业抄代码选手2 小时前
在react中,TSX是如何转变成JS的
前端·javascript
葡萄城技术团队2 小时前
【实践篇】从零到一:手把手教你搭建一套企业级 SpreadJS 协同设计器
前端
进击的尘埃2 小时前
SOLID 原则在 React 组件库里怎么落地:五个重构案例
javascript
忆江南3 小时前
# iOS Block 深度解析
前端
米丘3 小时前
vue-router v5.x 路由模式关于 createWebHistory、 createWebHashHistory的实现
前端