分析express-pjax

来源:互联网 发布:网络诈骗报警有用吗 编辑:程序博客网 时间:2024/05/25 12:21
先来看见express-pjax的源代码
module.exports = function() {  return function(req, res, next) {    if (req.header('X-PJAX')) {      req.pjax = true;    }    res.renderPjax = function(view, options, fn) {      if (req.pjax) {        if (options) {          options.layout = false;        } else {          options = {};          options.layout = false;        }      }      res.render(view, options, fn);    };    next();  };};

很简单,没毛病。就是将res.render()这个方法进行了‘加工’。

如果不是用他的方法我们想不使用layout,直接设置成:

res.render('index',{layout:false});

这个res.renderPjax()这个方法,就是让我们少写了一个 {layout:false}

默默地说一句,可以的很强势。

更多原创文章访问:meetqy.com

原创粉丝点击