vue3简易文字验证码

大神勿喷,简易版本,demo中可以用一下。

需要几个文字自己codelen 赋值 灵活点直接父组件传过去,可以自己改造在这里插入图片描述

首先创建一个生成数字的js

**mathcode.js**

function MathCode(num){let str = "寻寻觅觅冷冷清清凄凄惨惨戚戚乍暖还寒时候最难将息三杯两盏淡酒怎敌他晚来风急雁过也正伤心却是旧时相识满地黄花堆积憔悴损如今有谁堪摘守着窗儿独自怎生得黑梧桐更兼细雨到黄昏点点滴滴这次第怎一个愁字了得";let arr = str.split("");let lastcoe =  getArrayItems(arr,num) return lastcoe;
}//随机生成指定个数的字符function getArrayItems(arr, num) {var temp_array = new Array();for (var index in arr) {temp_array.push(arr[index]);}var return_array = new Array();for (var i = 0; i<num; i++) {if (temp_array.length>0) {var arrIndex = Math.floor(Math.random()*temp_array.length);return_array[i] = temp_array[arrIndex];temp_array.splice(arrIndex, 1);} else {    break;}}return return_array;
}export { MathCode }

组件如下TextCode.vue

<!--* @Author: “1077321622@qq.com” lzr448470520* @Date: 2023-09-27 14:01:19* @LastEditors: “1077321622@qq.com” lzr448470520* @LastEditTime: 2023-10-01 17:31:53* @FilePath: \viteapp\src\components\TextCode.vue* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
--><template><div class="mian"><el-dialogv-model="centerDialogVisible":title="title"width="400px"align-center:show-close="false":close-on-click-modal="false":close-on-press-escape="false"><div class="img_txt"><imgsrc="https://img2.baidu.com/it/u=3913729461,3658245748&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500"alt=""/><ul><liv-bind:style="{top: mathPosition() + 'px',left: mathPosition() + 'px',position: 'absolute',}":class="current === index ? 'bgColor' : ''"v-for="(item, index) in codelist":key="index"@click="handCode(item, index)">{{ item }}</li></ul></div><template #footer><span class="dialog-footer">{{ showtext }}<el-button type="primary" @click="Refresh"> 刷新 </el-button><el-button type="primary" :disabled="disbtn" @click="handSuccess">确认</el-button></span></template></el-dialog></div>
</template><script  setup>
import { MathCode } from "../units/mathcode.js";
import { ElMessage } from "element-plus";
import { ref } from "vue";
let centerDialogVisible = ref(true);
let disbtn = ref(true);
let codelen = ref(4);
let codelist = ref([]);
let title = ref("");
let clickItem = ref([]);
let showtext = ref("");
let current = ref("-1");
let fristtxt = ref("");
let returnBoolen = ref(false);const emit = defineEmits(["SelechChange"]);onMounted(() => {let str = MathCode(codelen.value);codelist.value = str;title.value = "请依次点击=>" + str;fristtxt.value = str.join("");
});//生成随机坐标
const mathPosition = () => {return parseInt(Math.random() * (280 - 20) + 20);
};//刷新验证
const Refresh = () => {let str = MathCode(codelen.value);codelist.value = str;title.value = "请依次点击=>" + str;clickItem.value = [];fristtxt.value = str.join("");showtext.value = "";returnBoolen.value = false;current.value = -1;
};const handCode = (item, index) => {current.value = index;if (clickItem.value.length < codelen.value) {clickItem.value.push(item);showtext.value = clickItem.value.join("");if (clickItem.value.join("") == fristtxt.value) {disbtn.value = false;returnBoolen.value = true;} else {disbtn.value = true;returnBoolen.value = false;if (clickItem.value.length == codelen.value) {ElMessage.error("验证码有误,请刷新重试");}}}
};const handSuccess = () => {if (returnBoolen.value) {centerDialogVisible.value = false;emit("SelechChange", returnBoolen.value);}
};
</script><style scoped>
.dialog-footer button:first-child {margin-right: 10px;
}
.img_txt {width: 100%;height: 350px;background: #f4f4f4;cursor: pointer;position: relative;
}
.img_txt img {width: 100%;height: 100%;position: absolute;top: 0;left: 0;
}
.img_txt ul {width: 100%;height: 100%;position: absolute;top: 0;left: 0;
}
.img_txt ul li {font-size: 30px;font-weight: bold;color: #fff;position: relative;
}
.bgColor {background-color: red;border-radius: 50%;padding: 5px;
}
</style>

使用方式在页面中引入

import TextCode from "./TextCode.vue";

例如 login.vue

<!--* @Author: your name* @Date: 2022-03-04 17:33:01* @LastEditTime: 2023-10-01 17:33:58* @LastEditors: “1077321622@qq.com” lzr448470520* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE* @FilePath: \viteapp\src\components\Login.vue
--><template><div class="logo"><div class="logo_center"><div class="logo_pic"><p class="p1"><img src="" alt="" /></p><p class="p2">vue3( setup 语法糖)开发听歌系统</p></div><div class="logo_input"><el-inputv-model="username"type="password"class="username"placeholder="请输入163邮箱账号"><template #suffix><el-icon class="el-input__icon"><Stamp /></el-icon></template></el-input><el-inputv-model="password"type="password"class="pass"placeholder="请输入密码"></el-input><div class="btn"><button class="btn" @click="gologin">登录</button><!-- <el-button type="success" style="width: 100%; height: 100%" plain @click="gologin">登录</el-button> --></div></div></div><TextCode  @SelechChange="SelechChange"></TextCode></div>
</template><script setup>
import { Login,Login1 } from "../api/index.js";
import { ElMessage } from "element-plus";
import TextCode from "./TextCode.vue";//l路由引入
import { useStore } from "vuex";
import Cookies from "js-cookie";
const username = ref("11111@163.com");
const password = ref("222222");
const router = useRouter();
const store = useStore();
let status =  ref(false);const SelechChange = (val)=>{// 赋值status.value = val;
};
//登录
const gologin = () => {if(status.value){//alert("写自己的逻辑")}else{ElMessage.error("请刷新页面点击正确验证码")}
};
</script>
<style lang="scss" scoped>
.logo {width: 100%;height: 100%;// background: url("../assets/login/logobj.png");background: firebrick;background-size: 100% 100%;background-repeat: no-repeat;position: relative;.logo_center {width: 395px;height: 435px;background: #fff;position: absolute;transform: translate(-50%, -50%);top: 50%;left: 50%;border-radius: 8px;.logo_pic {width: 100%;height: 170px;position: relative;.p1 {width: 120px;height: 95px;background: url("../assets/login/logopic.png");position: absolute;top: 25px;left: 0px;right: 0px;bottom: 0px;margin: auto;background-size: 100% 100%;background-repeat: no-repeat;position: relative;}.p2 {width: 100%;height: 20px;text-align: center;position: absolute;top: 140px;left: 0px;right: 0px;bottom: 0px; margin: auto;color: #606266;font-size: 15px;}}.logo_input {width: 70%;margin: 20px auto 0px auto;.pass {margin-top: 20px;}button {width: 100%;margin-top: 10px;--glow-color: rgb(217, 176, 255);--glow-spread-color: rgba(191, 123, 255, 0.781);--enhanced-glow-color: rgb(231, 206, 255);--btn-color: rgb(100, 61, 136);border: 0.25em solid var(--glow-color);padding: 1em 3em;color: var(--glow-color);font-size: 15px;font-weight: bold;background-color: var(--btn-color);border-radius: 1em;outline: none;box-shadow: 0 0 1em 0.25em var(--glow-color),0 0 4em 1em var(--glow-spread-color),inset 0 0 0.75em 0.25em var(--glow-color);text-shadow: 0 0 0.5em var(--glow-color);position: relative;transition: all 0.3s;}button::after {pointer-events: none;content: "";position: absolute;top: 120%;left: 0;height: 100%;width: 100%;background-color: var(--glow-spread-color);filter: blur(2em);opacity: 0.7;transform: perspective(1.5em) rotateX(35deg) scale(1, 0.6);}button:hover {color: var(--btn-color);background-color: var(--glow-color);box-shadow: 0 0 1em 0.25em var(--glow-color),0 0 4em 2em var(--glow-spread-color),inset 0 0 0.75em 0.25em var(--glow-color);}button:active {box-shadow: 0 0 0.6em 0.25em var(--glow-color),0 0 2.5em 2em var(--glow-spread-color),inset 0 0 0.5em 0.25em var(--glow-color);}.btn:hover::before {transform: translateX(0);}}}
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/146476.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

字符串函数与内存函数讲解

文章目录 前言一、字符串函数1.求字符串长度strlen 2.长度不受限制的字符串函数(1)strcpy(2)strcat(3)strcmp 3.长度受限制的字符串函数(1)strncpy(2)strncat(3)strncmp 4.字符串查找(1)strstr(2)strtok 5.错误信息报告(1)strerror(2)perror 二、内存函数1.memcpy2.memmove3.me…

如何开发物联网 APP?

如何开发物联网 APP? 这个问题本身是不严谨的&#xff0c;APP只是手机端的一个控制或者用于显示的人机交互页面&#xff0c;物联网是通过传感器&#xff0c;物联网卡等模块把物体接入网络以方便远程监控或者控制等。 你问的应该是怎么开发出来一个远程控制物体的APP吧&#x…

基于TDOA和FDOA的RSSI定位算法matlab仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 4.1TDOA&#xff08;Time Difference of Arrival&#xff09;定位算法 4.2 FDOA&#xff08;Frequency Difference of Arrival&#xff09;定位算法 5.算法完整程序工程 1.算法运行效果图预…

基于vue+Element Table Popover 弹出框内置表格的封装

文章目录 项目场景&#xff1a;实现效果认识组件代码效果分析 封装&#xff1a;代码封装思路页面中使用 项目场景&#xff1a; 在选择数据的时候需要在已选择的数据中对比选择&#xff0c;具体就是点击一个按钮&#xff0c;弹出一个小的弹出框&#xff0c;但不像对话框那样还需…

亘古难题:前端开发 or 后端开发

目录 一、引言二、两者的对比分析1. 技能要求和专业知识前端开发后端开发 2. 职责和工作内容前端开发后端开发 3. 项目类型和应用领域前端开发后端开发 4. 就业前景和市场需求前端开发后端开发 三、技能转换和跨领域工作四、介绍全栈开发五、结语附、开源项目微服务商城项目前后…

SimpleCG动画示例--汉诺塔动画演示

前言 SimpleCG的使用方法在前面已经介绍了许多&#xff0c;有兴趣的同学如果有去动手&#xff0c;制作一些简单动画应该没多大问题的。所以这次我们来演示一下简单动画。我们刚学习C语言的递归函数时&#xff0c;有一个经典例子相信很多同学都写过&#xff0c;那就是汉诺塔。那…

UE4 Cesium 与ultra dynamic sky插件天气融合

晴天&#xff1a; 雨天&#xff1a; 雨天湿度&#xff1a; 小雪&#xff1a; 中雪&#xff1a; 找到该路径这个材质&#xff1a; 双击点开&#xff1a; 将Wet_Weather_Effects与Snow_Weather_Effects复制下来&#xff0c;包括参数节点 找到该路径这个材质&#xff0c;双击点开&…

Linux CentOS7 vim重复行

在用vim编辑处理文件时&#xff0c;会有重复行。有的是情境需要&#xff0c;有的可能是误操作而形成。对于正常形成的重复行&#xff0c;我们不作讨论&#xff0c;我们仅讨论什么情况下会出现重复行&#xff0c;如何避免&#xff0c;如何处理。 在文件中的单行或多个连续空白行…

mysql的mvcc详解

一 MVCC的作用 1.1 mvcc的作用 1.MVCC&#xff08;Multiversion Concurrency Control&#xff09;多版本并发控制。即通过数据行的多个版本管理来实现数据库的并发控制&#xff0c;使得在InnoDB事务隔离级别下执行一致性读操作有了保障。 2.mysql中的InnoDB中实现了MVCC主要…

Qt Creator 预览界面 快捷键

一般来说&#xff0c;我们运行Qt程序所花费的时间是比较长的&#xff0c;那有时我们只改变了界面&#xff0c;那么此时花费如此长的时间去运行程序来观察界面改动的效果是非常浪费时间的行为。 此时我们可以选择预览界面来观察界面改动后的效果&#xff1a;

[Linux] 6.VMware虚拟机网络配置

在VMware虚拟机下可以在虚拟网络编辑器看到三种模式 一、Bridged&#xff08;桥接模式&#xff09; 桥接模式就是将主机网卡与虚拟机虚拟的网卡利用虚拟网桥进行通信。 真机、虚拟机都有自己的ip地址&#xff0c;能互相通讯&#xff0c;而且能上网。 功能齐全&#xff0c;但…

MySql出错点

一、DDL 1.修改表&#xff0c;添加新的字段时&#xff0c;不要加引号 2.在修改表中字段的类型时&#xff0c;会发生数据截断。 像DATETIME 转化为 TIME 二、DML 1.插入和删除的注意点 2.可以通过 select 来协助插入 3.

全连接网络实现回归【房价预测的数据】

也是分为data&#xff0c;model&#xff0c;train&#xff0c;test import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optimclass FCNet(nn.Module):def __init__(self):super(FCNet,self).__init__()self.fc1 nn.Linear(331,200)s…

java Spring Boot 将日志写入文件中记录

我们之前的一套操作来讲 日志都是在控制台上的 但 如果你的项目在正式环境上跑 运维人员突然告诉你说日志报错了&#xff0c;但你日志只在控制台上&#xff0c;那公司项目如果访问量很大 那你是很难在控制台上找到某一条日志的 这时 我们就可以用文件把它记下来 我们打开项目 …

[DS资源推荐] Data Structure 严书配套代码

下图引入自康建伟老师博客 Github地址 使用说明&#xff1a;康老师博客 使用感受&#xff1a;Orz&#xff01;非常非常非常全面&#xff01;终于能看得下去严书了…

【AI视野·今日NLP 自然语言处理论文速览 第四十期】Mon, 25 Sep 2023

AI视野今日CS.NLP 自然语言处理论文速览 Mon, 25 Sep 2023 Totally 46 papers &#x1f449;上期速览✈更多精彩请移步主页 Daily Computation and Language Papers ReConcile: Round-Table Conference Improves Reasoning via Consensus among Diverse LLMs Authors Justin C…

Linux性能优化--性能工具-系统CPU

2.0.概述 本章概述了系统级的Linux性能工具。这些工具是你追踪性能问题时的第一道防线。 它们能展示整个系统的性能情况和哪些部分表现不好。 1.理解系统级性能的基本指标&#xff0c;包括CPU的使用情况。 2.明白哪些工具可以检索这些系统级性能指标。2.1CPU性能统计信息 为了…

Redis BitMap+SpringBoot 实现签到与统计功能

前言&#xff1a; 在各个项目中&#xff0c;我们都可能需要用到签到和 统计功能。签到后会给用户一些礼品以此来吸引用户持续在该平台进行活跃。 签到功能&#xff0c;使用 Redis 中的 BitMap 功能来实现&#xff0c;就是一个非常不错的选择。 一、Redis BitMap 基本用法 Bi…

java - 七大比较排序 - 详解

前言 本篇介绍了七大比较排序&#xff0c;直接插入排序&#xff0c;希尔排序&#xff0c;冒泡排序&#xff0c;堆排序&#xff0c;选择排序&#xff0c;快速排序&#xff0c;归并排序&#xff0c;一些简单思想代码实现&#xff0c;如有错误&#xff0c;请在评论区指正&#xf…

竞赛选题 大数据疫情分析及可视化系统

文章目录 0 前言2 开发简介3 数据集4 实现技术4.1 系统架构4.2 开发环境4.3 疫情地图4.3.1 填充图(Choropleth maps)4.3.2 气泡图 4.4 全国疫情实时追踪4.6 其他页面 5 关键代码最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; 大数据疫…