推荐一款前端滑动验证码插件(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

相关推荐
IT_陈寒26 分钟前
Vite静态资源加载把我坑惨了
前端·人工智能·后端
herinspace27 分钟前
管家婆实用贴-如何分离和附加数据库
开发语言·前端·javascript·数据库·语音识别
小码哥_常1 小时前
从MVC到MVI:一文吃透架构模式进化史
前端
嗷o嗷o1 小时前
Android BLE 的 notify 和 indicate 到底有什么区别
前端
豹哥学前端1 小时前
别再背“var 提升,let/const 不提升”了:揭开暂时性死区的真实面目
前端·面试
Lkstar1 小时前
我把Vue2响应式源码从头到尾啃了一遍,这是整理笔记
vue.js
lar_slw1 小时前
k8s部署前端项目
前端·容器·kubernetes
这里不能睡觉2 小时前
js 实现 Blob、File、ArrayBuffer、base64、URL 之间互转
javascript
拉拉肥_King2 小时前
Ant Design Table 横向滚动条神秘消失?我是如何一步步找到真凶的
前端·javascript
GreenTea2 小时前
DeepSeek-V4 技术报告深度分析:基础研究创新全景
前端·人工智能·后端