公式
offset = (currentPage - 1) * pageSize
// admin/articles.js
router.get('/', async function (req, res, next) {
try {
const currentPage = Math.abs(Number(req.query.currentPage)) || 1;
const pageSize = Math.abs(Number(req.query.pageSize)) || 10;
const offset = (currentPage - 1) * pageSize
const condition = {
order: [['id', "DESC"]],
limit: pageSize,
offset: offset
}
const { title } = req.query
if (title) {
condition["where"] = {
title: {
[Op.like]: `%${title}%`
}
}
}
const { count, rows } = await Article.findAndCountAll(condition);
res.json({
status: true,
message: "查询列表成功。",
data: rows,
pagination: {
count,
currentPage,
pageSize
}
});
} catch (error) {
res.status(500).json({
error
})
}
});












网友评论