1.创建工具类
根目录/config/tools.js
const bcrypt = require('bcryptjs'); const tools = { enbcrypt(password) { var salt = bcrypt.genSaltSync(10); var hash = bcrypt.hashSync(password, salt); return hash; } }; module.exports = tools;
2.引用
根目录/routes/api/users.js
const tools = require('../../config/tools'); ... password: tools.enbcrypt(ctx.request.body.password)
3.效果图