vue 滑块验证组件 笔记

vue-drag-verify

1、vue-drag-verify组件

// 基本滑块验证组件
npm i vue-drag-verify2 -S
// 图片滑块组件
npm i vue-drag-verify-img -S
// 基本滑块验证组件(拼图)
npm i vue-drag-verify-img-chip -S
// 旋转图片滑块组件
npm i vue-drag-verify-img-rotate -S

 2、代码

// main.js

import Vue from 'vue'
import App from './App.vue'
import dragVerify from 'vue-drag-verify2'
Vue.use(dragVerify)

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

new Vue({
  el: '#app',
  render: h => h(App)
});

2.1、基本滑块验证组件

<template>
    <div>
        <el-row>
            <drag-verify
                    ref="dragVerify"
                    :isPassing.sync="isPassing1"
                    handlerIcon="el-icon-d-arrow-right"
                    successIcon="el-icon-circle-check"
            >
            </drag-verify>
        </el-row>
        <el-row style="margin-top:10px">
            <drag-verify
                    ref="dragVerify"
                    :isPassing.sync="isPassing2"
                    text="请按住滑块拖动"
                    successText="验证通过"
                    handlerIcon="el-icon-d-arrow-right"
                    successIcon="el-icon-circle-check"
            >
            </drag-verify>
        </el-row>
        <el-row style="margin-top:10px;">
            <drag-verify
                    ref="dragVerify"
                    :isPassing.sync="isPassing3"
                    completedBg="#93a6ff"
                    text="请按住滑块拖动"
                    successText="验证通过"
                    handlerIcon="el-icon-arrow-right"
                    successIcon="el-icon-check"
            >
            </drag-verify>
        </el-row>
        <el-row style="margin-top:10px;">
            <drag-verify
                    ref="dragVerify"
                    :isPassing.sync="isPassing4"
                    :circle="true"
                    text="请按住滑块拖动"
                    successText="验证通过"
                    handlerIcon="el-icon-d-arrow-right"
                    successIcon="el-icon-circle-check"
            >
            </drag-verify>
        </el-row>
        <el-row style="margin-top:10px;">
            <drag-verify
                    ref="dragVerify"
                    :width="300"
                    :isPassing.sync="isPassing5"
                    text="请按住滑块拖动"
                    successText="验证通过"
                    background="#ccc"
                    completedBg="rgb(105, 231, 251)"
                    handlerIcon="el-icon-d-arrow-right"
                    successIcon="el-icon-circle-check"
                    @passcallback="passcallback"
            >
            </drag-verify>
        </el-row>

        <el-row style="margin-top:10px;">
            <drag-verify
                    ref="dragVerify"
                    :width="300"
                    :isPassing.sync="isPassing6"
                    text="请按住滑块拖动"
                    successText="验证通过"
                    handlerIcon="el-icon-d-arrow-right"
                    successIcon="el-icon-circle-check"
                    @passcallback="passcallback2"
            >
                <i
                        v-show="!isPassing6"
                        slot="textBefore"
                        class="el-icon-lock"
                ></i>
            </drag-verify>
        </el-row>

        <el-row style="margin-top:10px;">
            <drag-verify
                    ref="dragVerify7"
                    :width="300"
                    :isPassing.sync="isPassing7"
                    text="请按住滑块拖动 (可还原)"
                    successText="验证通过"
                    handlerIcon="el-icon-d-arrow-right"
                    successIcon="el-icon-circle-check"
                    @passcallback="passcallback3"
            >
            </drag-verify>
            <el-button
                    style="margin-top:5px;"
                    size="small"
                    @click="reset"
            >还原</el-button>
        </el-row>
    </div>
</template>

<script>
    export default {
        name: "HuaKuai",
        data() {
            return{
                isPassing7: false,
                isPassing6: false,
                isPassing5: false,
                isPassing4: false,
                isPassing3: false,
                isPassing2: false,
                isPassing1: false
            }
        },
        methods:{
            passcallback(){
                this.$message({
                    message: '验证通过',
                    type: 'success'
                });
            },
            passcallback2(){
                this.$message({
                    message: '验证通过',
                    type: 'success'
                });
            },
            passcallback3(){
                this.$message({
                    message: '验证通过',
                    type: 'success'
                });
            },
            reset() {
                this.isPassing7 = false;
                this.$refs.dragVerify7.reset();
            },
        }
    }
</script>

<style scoped>

</style>

2.2、图片滑块组件

<el-row>
  <drag-verify-img 
    ref="sss"
    :imgsrc="t3"
    :isPassing.sync="isPassing"
    :showRefresh="true"
    text="请按住滑块拖动"
    successText="验证通过"
    handlerIcon="el-icon-d-arrow-right"
    successIcon="el-icon-circle-check"
    @refresh="reimg"
    @passcallback="pass"
    @passfail="handleFail"
  >
  </drag-verify-img>
  <label for="">验证失败自动更新滑块位置</label>
  <el-switch
    v-model="value"
  >
  </el-switch>
  <el-button type="primary" @click="reset">还原</el-button>
</el-row>

<script>
  export default{
    methods:{
      handleFail() {
        if(this.value){
          setTimeout(()=>{
            this.$refs.sss.reset();
          },500)
        }
      },
    }
  }
</script>

2.3、图片滑块拼图组件

<el-row>
            <drag-verify-img-chip
                    ref="sss"
                    :imgsrc="img"
                    :isPassing.sync="isPassing"
                    :showRefresh="true"
                    :barWidth="40"
                    text="请按住滑块拖动"
                    successText="验证通过"
                    handlerIcon="el-icon-d-arrow-right"
                    successIcon="el-icon-circle-check"
                    @refresh="reimg"
                    @passcallback="pass"
                    @passfail="huanYuan2('失败')"
            >
            </drag-verify-img-chip>
            <el-button type="primary" @click="huanYuan2('还原')">还原</el-button>
        </el-row>

2.4、旋转图片滑块组件

<el-row>
  <drag-verify-img 
    ref="sss"
    :imgsrc="t3"
    :isPassing.sync="isPassing"
    text="请按住滑块拖动"
    successText="验证通过"
    handlerIcon="el-icon-d-arrow-right"
    successIcon="el-icon-circle-check"
    @refresh="reimg"
    @passcallback="pass"
  >
  </drag-verify-img>
  <el-button type="primary" @click="reset">还原</el-button>
</el-row>

3、效果图

 

 

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值