blue
  • 3
  • 新人请关照

koa 异步返回ctx.body eslint 报错 require-atomic-updates

module.exports = async (ctx) => {

const reqUrl = ctx.request.header.referer;
const urlParam = url2param(reqUrl);
const offset = (urlParam.page - 1) * urlParam.pageSize;
try {
// 获取数据库数据
    const data = await User.findAndCountAll({
        attributes: [
            'username',
            'realname',
            'phone',
            'roleType',
            'hasActive',
            'createdAt'
        ],
        offset,
        limit: +urlParam.pageSize
    });
    // 将数据返回给前端
    ctx.body = {data};    //eslint报错  require-atomic-updates
} catch (e) {
    ctx.body = {...e};    //eslint报错  require-atomic-updates
}

};

前端返回数据无误,但是
eslint报错信息:
Possible race condition: ctx.body might be reassigned based on an outdated value of ctx.body.

没弄明白为什么,不知问题出在哪.

阅读 1.6k
评论
    4 个回答
    mebtte
    • 363
    评论 赞赏