对象有指向属性,可以转化后比较
JSON.stringify(list).includes(JSON.stringify(user))
例
async login(){
const user={
username:this.ctx.request.body.username,
password:this.ctx.request.body.password
}
let list = await this.app.model.User.findAll({
attributes: ['username', 'password'],
//查询出包含username和password的数据
})
let token = this.app.jwt.sign(user, this.app.config.jwt.secret)
if (JSON.stringify(list).includes(JSON.stringify(user))) {
this.ctx.body={
code:200,
msg:'登录成功',
token:token
}
} else {
this.ctx.body = {
code:500,
msg:'登录失败',
}
}
}