这是egg代码
'use strict';
const Service = require('egg').Service;
class UserService extends Service {
async login() {
// const md5=require('md5-node');
let name = this.ctx.request.body.name;
let password = this.ctx.request.body.password
let log = await this.app.model.Log.findOne({
where:{
name:name,
}
});
if(log == null){
// this.ctx.body = "用户不存在";
return"用户不存在"
}else
// 判断密码是否正确,正确则登录成功
if(password == log.password){
// this.ctx.session.user = user; //设置session
return"登陆成功"
}else{
return"密码错误"
}
}
}
module.exports = UserService;
vue代码
login() {
axios
.post("http://127.0.0.1:7001/login", {
name: this.name,
password: this.password
})
.then(res => {
if (res.data == "登录成功") {
alert("登陆成功")
// this.$router.push({ name: "Home_page" });
}else
console.log(res.data)
if (res.data == "用户不存在") {
alert("用户不存在");
}
if (res.data == "密码错误!") {
alert("密码错误!");
}
})
.catch(err => {
console.log(err);
});
希望各位大佬解答### 问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)