react 组件实战之 验证码

主要功能:

  • 随机生成4个 大 / 小写英文字母 / 阿拉伯数字
  • 随机干扰线防止机器轻松破解
  • 点击刷新验证码
  • dom 结构优化

验证码一定是人类史上比较伟大的发明,坑了机器人也坑了自己。
最难验证码
最难验证码
来有兴趣的小伙伴请留言验证码输入答案!!

言归正传,验证码的功能主要是

不被机器轻松破解
人眼很好识别

完整代码: https://github.com/zzzzhaoziyi/react-Vcode
效果预览 效果阅览

第一步随机生成4个 大 / 小写英文字母 / 阿拉伯数字

  getRandom(max, min, num) {
    const asciiNum = ~~(Math.random()*(max-min+1)+min)
    if(!Boolean(num)){
      return asciiNum
    }
    const arr = []
    for(let i = 0; i < num; i++){
      arr.push(this.getRandom(max, min
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你可以使用 React Swipeable 库来实现基于 React 的滑动图片验证组件。该库提供了一个 Swipeable 组件,可以帮助你快速实现滑动操作。 下面是一个基本的滑动图片验证组件的示例: ```jsx import React, { useState } from 'react'; import Swipeable from 'react-swipeable'; const SlideCaptcha = ({ onSuccess, onFailure }) => { const [isSliding, setIsSliding] = useState(false); const [sliderPosition, setSliderPosition] = useState(0); const [sliderWidth, setSliderWidth] = useState(0); const handleSwipeStart = () => { setIsSliding(true); }; const handleSwipeMove = (event, deltaX) => { if (!isSliding) return; const newSliderPosition = Math.max(0, Math.min(sliderWidth, sliderPosition + deltaX)); setSliderPosition(newSliderPosition); }; const handleSwipeEnd = () => { setIsSliding(false); if (sliderPosition >= sliderWidth * 0.9) { onSuccess(); } else { onFailure(); setSliderPosition(0); } }; const handleSliderRef = (node) => { if (node) { setSliderWidth(node.offsetWidth); } }; return ( <div> <div className="captcha-image" /> <Swipeable className="slider" onSwiping={handleSwipeMove} onSwipingStart={handleSwipeStart} onSwipingEnd={handleSwipeEnd} > <div className="slider-inner" ref={handleSliderRef}> <div className="slider-handle" style={{ left: sliderPosition }} /> </div> </Swipeable> </div> ); }; export default SlideCaptcha; ``` 在这个示例中,我们使用 Swipeable 组件来监听滑动事件,并根据滑动距离来移动滑块的位置。当滑块移动到指定位置时,触发 onSuccess 回调函数。如果滑块没有移动到指定位置,将调用 onFailure 回调函数并将滑块重置。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值