1.jwt学习
标头,有效载荷,签名
const jwt = require('jsonwebtoken')
const user = { ...req.body, pwd: '' }
const tokenStr = jwt.sign(user, config.jwtSerectKey, {
expiresIn: '100000'//有效期为10个小时
})
res.send({
status: 0,
message: '登录成功',
token: 'Bearer ' + tokenStr//Bearer后面的空格不能丢
})
jwt.verify(token, config.jwtSerectKey, (err) => {
if (err) {
res.cc(err)
} else {
res.cc('已登录', 0)
}
})
2.urlencoded格式
又叫form格式,或者是x-www-form-urlencoded格式
content-type 可以选择 x-www-form-urlencoded 格式
例子:https://www.baidu.com/s?ie=UTF-8&wd=baidu
3.请求与响应
4.关于对象解构
const test = {
a: 10,
b: 20
}
const res = { ...test, b: 40 }
console.log(res);// { a: 10, b: 40 }
5.bcryptjs加密
(1)使用场景1
对用户密码进行加密后存入数据库,bcryptjs.hashSync
const pwd = bcryptjs.hashSync(req.body.pwd, 10)
(2)使用场景2
在登录操作中,需要确保输入的密码和数据库中被加密的密码相匹配,bcryptjs.compareSync
返回true表示密码正确,fasle为密码错误
if (!bcryptjs.compareSync(req.body.pwd, results[0].password)) {
return res.cc('密码错误')
}
6.背景图片不随滚动条滚动
background-attachment: fixed;
7.关于notfound页面
匹配所有路径vue2使用*
vue3使用/:pathMatch(.*)*或/:pathMatch(.*)或/:catchAll(.*)