利用JSON.stringify()把对象转为对象字符串,可去掉RowDataPacket。
router.post('/login', function (req, res) {
let { username, password } = req.body
const sqlStr = `select * from account where username= '${username}' and password='${password}'`
connection.query(sqlStr, (err, data) => {
if (err) {
throw err
} else {
console.log('data', data)
let results = JSON.stringify(data);//把results对象转为字符串,去掉 RowDataPacket
let obj= JSON.parse(results ); //把results对象转为字符串,去掉 RowDataPacket
console.log('去掉了RowDataPacket',results);
}
})
});