vue 滑动验证码(vue登陆如何获取token)

之前别人都是用jq写的,自己整理了一下开始使用<el-form-itemlabel="验证"><divclass="form-inline-input"><divclass="code-box"id="code-box">

大家好,又见面了,我是你们的朋友全栈君。

之前别人都是用jq写的,自己整理了一下开始使用

<
el-form-item
label=
“验证”>
<
div
class=
“form-inline-input”>
<
div
class=
“code-box”
id=
“code-box”>
<
input
type=
“text”
name=
“code”
class=
“code-input” />
<
p></
p>
<
span>>>></
span>
</
div>
</
div>
</
el-form-item>

vue代码

//获取元素距离页面边缘的距离
getOffset(
box,
direction){
var setDirection
= (direction
==
‘top’)
?
‘offsetTop’
:
‘offsetLeft’ ;
var offset
= box[setDirection];
var parentBox
=
box.
offsetParent;
while(parentBox){
offset
+=parentBox[setDirection];
parentBox
=
parentBox.
offsetParent;
}
parentBox
=
null;
return
parseInt(offset);
},
    moveCode(
code,
_this){
var fn
= {codeVluae : code};
var box
=
document.
querySelector(
“#code-box”),
progress
=
box.
querySelector(
“p”),
codeInput
=
box.
querySelector(
‘.code-input’),
evenBox
=
box.
querySelector(
“span”);
//默认事件
var boxEven
= [
‘mousedown’,
‘mousemove’,
‘mouseup’];
//改变手机端与pc事件类型
if(
typeof
document.
ontouchstart
==
‘object’){
boxEven
= [
‘touchstart’,
‘touchmove’,
‘touchend’];
}
var goX,offsetLeft,deviation,evenWidth,endX;
function
moveFn(
e){
e.
preventDefault();
e
= (boxEven[
‘0’]
==
‘touchstart’)
?
e.
touches[
0]
: e
||
window.
event;
endX
=
e.
clientX
goX;
endX
= (endX
>
0)
? (endX
> evenWidth)
? evenWidth
: endX
:
0;
if(endX
> evenWidth
*
0.7){
progress.
innerText
=
‘松开验证’;
progress.
style.
backgroundColor
=
“#66CC66”;
}
else{
progress.
innerText
=
;
progress.
style.
backgroundColor
=
“#FFFF99”;
}
progress.
style.
width
= endX
+deviation
+
‘px’;
evenBox.
style.
left
= endX
+
‘px’;
}
function
removeFn() {
document.
removeEventListener(boxEven[
‘2’],removeFn,
false);
document.
removeEventListener(boxEven[
‘1’],moveFn,
false);
if(endX
> evenWidth
*
0.7){
progress.
innerText
=
‘验证成功’;
progress.
style.
width
= evenWidth
+deviation
+
‘px’;
evenBox.
style.
left
= evenWidth
+
‘px’
codeInput.
value
=
fn.
codeVluae;
evenBox.
onmousedown
=
null;
_this.
ruleForm.
verification
=
true;
}
else{
progress.
style.
width
=
‘0px’;
evenBox.
style.
left
=
‘0px’;
}
};
function
getOffset(
box,
direction){
var setDirection
= (direction
==
‘top’)
?
‘offsetTop’
:
‘offsetLeft’ ;
var offset
= box[setDirection];
var parentBox
=
box.
offsetParent;
while(parentBox){
offset
+=parentBox[setDirection];
parentBox
=
parentBox.
offsetParent;
}
parentBox
=
null;
return
parseInt(offset);
};
evenBox.
addEventListener(boxEven[
‘0’],
function(
e) {
e
= (boxEven[
‘0’]
==
‘touchstart’)
?
e.
touches[
0]
: e
||
window.
event;
goX
=
e.
clientX,
offsetLeft
=
getOffset(box,
‘left’),
deviation
=
this.
clientWidth,
evenWidth
=
box.
clientWidth
deviation,
endX;
document.
addEventListener(boxEven[
‘1’],moveFn,
false);
document.
addEventListener(boxEven[
‘2’],removeFn,
false);
},
false);
fn.
setCode
=
function(
code){
if(code)
fn.
codeVluae
= code;
}
fn.
getCode
=
function(){
return
fn.
codeVluae;
}
fn.
resetCode
=
function(){
evenBox.
removeAttribute(
‘style’);
progress.
removeAttribute(
‘style’);
codeInput.
value
=
;
};
return fn;
    }

调用

mounted(){
var _this
=
this;
// window.addEventListener(‘load’,function(){
//code是后台传入的验证字符串
var code
=
“jsaidaisd656”,
codeFn
=
new
_this.
moveCode(code,_this);
// });
}

验证样式

.form-inline-input{
  
border:
1
px
solid
#dadada;
border-radius:
5
px;
}
.form-inline-input
input,
.code-box{
  
padding:
0
3
px;
width:
298
px;
height:
40
px;
color:
#fff;
text-shadow:
1
px
1
px
1
px
black;
background:
#efefef;
border:
0;
border-radius:
5
px;
  
outline:
none;
}
.code-box{
  
position:
relative;
}
.code-box
p,
.code-box
span{
  
display:
block;
  
position:
absolute;
  
left:
0;
  
height:
40
px;
  
text-align:
center;
  
line-height:
40
px;
  
border-radius:
5
px;
padding:
0;
margin:
0;
}
.code-box
span{
  
width:
40
px;
  
background-color:
#fff;
  
font-size:
16
px;
  
cursor:
pointer;
margin-right:
1
px;
}
.code-box
p{
  
width:
0;
  
background-color:
#FFFF99;
  
overflow:
hidden;
  
text-indent:
-20
px;
  
transition:
background
1
s
ease-in;
}
.code-box
.code-input{
  
display:
none;
}
.code-box
.code-input{
  
display:
none;
}

.form-inline-input{
  
border:
1
px
solid
#dadada;
border-radius:
5
px;
}
.form-inline-input
input,
.code-box{
  
padding:
0
3
px;
width:
298
px;
height:
40
px;
color:
#fff;
text-shadow:
1
px
1
px
1
px
black;
background:
#efefef;
border:
0;
border-radius:
5
px;
  
outline:
none;
}
.code-box{
  
position:
relative;
}
.code-box
p,
.code-box
span{
  
display:
block;
  
position:
absolute;
  
left:
0;
  
height:
40
px;
  
text-align:
center;
  
line-height:
40
px;
  
border-radius:
5
px;
padding:
0;
margin:
0;
}
.code-box
span{
  
width:
40
px;
  
background-color:
#fff;
  
font-size:
16
px;
  
cursor:
pointer;
margin-right:
1
px;
}
.code-box
p{
  
width:
0;
  
background-color:
#FFFF99;
  
overflow:
hidden;
  
text-indent:
-20
px;
  
transition:
background
1
s
ease-in;
}
.code-box
.code-input{
  
display:
none;
}
.code-box
.code-input{
  
display:
none;
}

展示

vue 滑动验证码(vue登陆如何获取token)vue 滑动验证码(vue登陆如何获取token)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/129433.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 使用FFmpeg命令行进行UDP、RTP推流(H264、TS),ffplay接收

    使用FFmpeg命令行进行UDP、RTP推流(H264、TS),ffplay接收我们在开发网络程序时经常用到UDP或RTP来发送和接收流媒体,而开发程序完毕需要搭建一个环境测试,这时候可能你需要一个推流端或接收端。对于推流端,我们可以借助FFmpeg工具轻松完成该功能,只需要敲一条命令后就可以实现发流,并且支持多种网络协议(UDP/RTP/RTSP/RTMP)。而接收端我们可以使用ffplay,这个程序也是在FFmpeg工具包的Bin目录里面。大家可以根据自己需要使用这两个工…

    2022年6月15日
    326
  • 中断-NVIC与EXTI外设详解(超全面)

    中断-NVIC与EXTI外设详解(超全面)一.NVIC-嵌套向量中断控制器NVIC:嵌套向量中断控制器,属于内核外设,管理着包括内核和片上所有外设的中断相关的功能。这里解释一下片上外设与内核外设他们都在芯片里面,但内核外设是在内核CPU里面,片上外设就是内核之外咯。NVIC是嵌套向量中断控制器,控制着整个芯片中断相关的功能,它跟内核紧密耦合,是内核里面的一个外设。但是各个芯片厂商在设计芯片的时候会对Cortex-M3内核里面的NVIC进行裁剪,把不需要的部分去掉,所以STM32的NVIC是Cortex-M3的NVIC

    2022年5月8日
    50
  • erp学习交流社区

    erp学习交流社区[size=x-large]Hi,我是李彬,在ERP100俱乐部上建立了个人主页,邀请你也加入并成为我的好友。请加入到我的好友中,你就可以通过我的个人主页了解我的近况,分享我的照片,随时与我保持联系。邀请附言:请你点击以下链接,接受好友邀请:http://hi.erp100.com/invite.php?u=185659&c=9340c471d7847b99…

    2022年10月21日
    3
  • Java集合List去重的几种方式「建议收藏」

    Java集合List去重的几种方式「建议收藏」1、使用LinkedHashSet删除arraylist中的重复数据LinkedHashSet是在一个ArrayList删除重复数据的最佳方法。LinkedHashSet在内部完成两件事: 删除重复数据 保持添加到其中的数据的顺序 Java示例使用LinkedHashSet删除arraylist中的重复项。在给定的示例中,numbersList是包含整数的arraylist,其中一些是重复的数字。例如1,3和5.我们将列表添加到LinkedHashSet,然后将内容返回到列表中。

    2022年5月9日
    424
  • java物联网架构图_java物联网程序设计基础

    java物联网架构图_java物联网程序设计基础物联网架构成长零、说明  说明一下,我写的博客,都是我自己实践后,写下记录,方便以后自己看而已。没有什么系统的教学教程。也没有对底层的原理进行讲解,我觉得这些目前不是我需要注重的,作为一个开发人员,快速实现好需求才是最重要的。而作为一名合格的架构负责人,又必须了解底层,因此需要系统学习的,建议读者看官方文档或者对应的书籍。一、基础  【http://www.cnblogs.com/…

    2022年9月18日
    1
  • QCustomPlot使用

    QCustomPlot使用一、官网下载QCustomPlot官网下载从官网下载qcustomplot.h和qcustomplot.cpp二、加入工程通过添加现有文件将qcustomplot.h、qcustomplot.cpp加入工程,并在pro文件中加入printsupport三、使用

    2022年10月17日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号