您现在的位置是:网站首页> 编程资料编程资料
Vue考试系统的后台管理功能开发示例解读_javascript技巧_
2023-05-24
365人已围观
简介 Vue考试系统的后台管理功能开发示例解读_javascript技巧_
考试系统后台管理项目介绍:
技术选型:Vue2.0+Elemenu-ui
项目功能介绍:
- 账户信息模块:菜单权限、角色权限设置、角色权限分配、账号设置、公司分组
- 考试管理模块:新增/编辑/删除考试试题、成绩查看、阅卷评分、成绩记录、成绩导出
- 题库管理模块:批量导入考题、批量删除考题、编辑录入考题、新增/编辑/删除考试分类
登录界面
- 利用cookie实现,实现记住密码功能,下次打开页面自动补全,设置有效期为7天;
- 账号、密码验证;
- 点击登录调用接口跳转后台首页


login.vue组件代码:
考试系统后台管理
用户登录
记住密码 登录 版权********
data定义数据:
rules定义账号密码验证规则,可自定义规则
data() { return { logining: false, rememberpwd: false, ruleForm: { loginAccount: "", password: "" }, rules: { loginAccount: [ { required: true, message: "请输入账号", trigger: "blur" } ], password: [{ required: true, message: "请输入密码", trigger: "blur" }] } }; },methods方法:
添加点击键盘Enter的判断,点击之后触发登录,调用登录接口
// 键盘enter注册事件 loginIn(){ let keyCode = window.event.keyCode; console.log(this.$route.path,"登录path") if(keyCode == 13 && this.$route.path=="/login"){ this.$refs.ruleForm.validate(valid => { if (valid) { this.logining = true; this.loginFun(); } else { this.$message.error("请输入用户名密码!"); this.logining = false; return false; } }); }else{ return; } },可以手动点击登录调用登录接口,也可以使用Enter键调用登录
methods: { // 获取用户名密码 getuserpwd() { // 如果缓存里面有记录,就直接获取登录 if (getCookie("user") != "" && getCookie("pwd") != "") { this.ruleForm.loginAccount = getCookie("user"); this.ruleForm.password = getCookie("pwd"); this.rememberpwd = true; } }, // 登录方法封装 async loginFun() { const res = await login(this.ruleForm); console.log(res, "res登录"); if (res.code == 200) { if (this.rememberpwd == true) { //保存帐号到cookie,有效期7天 setCookie("user", this.ruleForm.loginAccount, 7); //保存密码到cookie,有效期7天 setCookie("pwd", this.ruleForm.password, 7); } else { delCookie("user"); delCookie("pwd"); } setTimeout(() => { this.logining = false; this.$router.push("/first/first"); this.$message({ message: "登录成功", type: "success" }); }, 1000); } else { this.$message.error(res.msg); this.logining = false; return false; } }, submitForm(ruleForm) { this.$refs[ruleForm].validate(valid => { if (valid) { this.logining = true; // 调用登录接口 this.loginFun(); } else { this.$message.error("请输入用户名密码!"); this.logining = false; return false; } }); }, // 键盘enter注册事件 loginIn(){ let keyCode = window.event.keyCode; console.log(this.$route.path,"登录path") if(keyCode == 13 && this.$route.path=="/login"){ this.$refs.ruleForm.validate(valid => { if (valid) { this.logining = true; this.loginFun(); } else { this.$message.error("请输入用户名密码!"); this.logining = false; return false; } }); }else{ return; } }, },点击记住密码方法调用:进入到页面进行读取
created() { this.getuserpwd(); },键盘Enter事件监听:
mounted(){ window.addEventListener('keydown',this.loginIn); }, destroyed(){ window.removeEventListener('keydown',this.loginIn,false); }登录接口引入:
import { login } from "../api/userMG";封装的cookie方法引入:
import { setCookie, getCookie, delCookie } from "../utils/utils";utils.js公共方法:
/** * 设置cookie **/ function setCookie(name, value, day) { let date = new Date(); date.setDate(date.getDate() + day); document.cookie = name + '=' + value + ';expires=' + date; }; /** * 获取cookie **/ function getCookie(name) { let reg = RegExp(name + '=([^;]+)'); let arr = document.cookie.match(reg); if (arr) { return arr[1]; } else { return ''; } }; /** * 删除cookie **/ function delCookie(name) { setCookie(name, null, -1); };到此这篇关于Vue考试系统的后台管理功能开发示例解读的文章就介绍到这了,更多相关Vue考试系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- Vue中为什么不推荐用index做key详解_vue.js_
- vue中计算属性和方法的区别及说明_vue.js_
- Vue中前端与后端如何实现交互_vue.js_
- vue中引入高德地图并多点标注的实现步骤_vue.js_
- Vue向后端传数据后端接收为null问题及解决_vue.js_
- Vue项目引用百度地图并实现搜索定位等功能(案例分析)_vue.js_
- vue引入jquery时报错 $ is not defined的问题及解决_vue.js_
- Element中el-input密码输入框浏览器自动填充账号密码问题的解决方法_vue.js_
- vue中Axios的封装和API接口的管理示例详解_vue.js_
- vue在body和query中如何向后端传参_vue.js_
