vue uniapp 统一验证码滑块验证

前言 (vue-puzzle-vcode)

发送验证码以及登录的时候会做验证,防止机刷等
效果图
在这里插入图片描述

一、安装依赖

npm install vue-puzzle-vcode --save

二、使用步骤

1.html使用

<Vcode :show="isShow" @success="onSuccess"/>

2.js

import Vcode from "vue-puzzle-vcode";
  export default {
    data(){
      return {
        isShow: false, // 验证码模态框是否出现
      }
    },
    components:{
      Vcode
    },
    methods:{// 用户通过了验证
      success(){
        this.isShow = false; // 通过验证后,需要手动隐藏模态框
      },
    }
  }

3.参数说明

字段类型默认值说明
showBooleanfalse是否显示验证码弹框
canvasWidthNumber310主图区域的宽度
canvasHeightNumber160主图区域的高度
imgsArraynull自定义图片,见下方例子
successTextString验证通过验证成功时的提示文字
failTextString“验证失败,请重试”验证失败时的提示文字
sliderTextString“拖动滑块完成拼图”下方滑动条里的文字

4.事件

事件名返回值说明
success偏差值验证通过时会触发,返回值是用户移动的距离跟目标距离的偏差值px
fail偏差值验证失败时会触发,返回值同上
closenull用户点击遮罩层的回调

5.图片太丑,自定义

html

<template>
  <Vcode :imgs="[Img1, Img2]" />
</template>

js

<script>
//注意图片路径
import Img1 from '~/assets/img1.png';
import Img2 from '~/assets/img2.png';
 
export default {
  data(){
    return {
      Img1,
      Img2
    }
  }
}
</script>
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp中,可以使用uni-simple-router插件来实现手机号验证码验证。具体步骤如下: 1. 安装uni-simple-router插件 ``` npm install uni-simple-router --save ``` 2. 在main.js中引入插件 ```js import Vue from 'vue' import App from './App' import router from './router' import USR from 'uni-simple-router' Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ ...App, router }) app.$mount() // 使用uni-simple-router插件 Vue.use(USR, { router }) ``` 3. 在需要验证的页面中添加验证码输入框和发送验证码按钮,并绑定相应的事件。 ```html <template> <view> <input type="tel" v-model="phone" placeholder="请输入手机号"/> <input type="tel" v-model="code" placeholder="请输入验证码"/> <button @click="sendCode">发送验证码</button> <button @click="submit">提交</button> </view> </template> <script> export default { data () { return { phone: '', code: '' } }, methods: { sendCode () { // 发送验证码逻辑 }, submit () { // 提交逻辑 } } } </script> ``` 4. 在发送验证码的方法中,通过uni.request发送请求获取验证码,并将验证码存储在本地。 ```js sendCode() { uni.request({ url: 'xxx/sendCode', data: { phone: this.phone }, success: (res) => { // 将验证码存储在本地 uni.setStorageSync('code', res.data.code) } }) } ``` 5. 在提交的方法中,获取用户输入的验证码和本地存储的验证码进行比对,判断验证是否通过。 ```js submit() { const code = uni.getStorageSync('code') if (this.code === code) { // 验证通过 } else { // 验证失败 } } ``` 以上就是在uniapp中实现手机号验证码验证的基本步骤。需要注意的是,发送验证码验证码验证的具体实现需要根据后端接口来进行调整。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值