Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs中视图助手的使用 #4

Open
milixie opened this issue Nov 3, 2016 · 0 comments
Open

nodejs中视图助手的使用 #4

milixie opened this issue Nov 3, 2016 · 0 comments

Comments

@milixie
Copy link
Owner

milixie commented Nov 3, 2016

1.app.js中:

var helper = require('./routes/helper');

app.use('/helper', helper);

app.locals.inspect = function(obj) {
    return util.inspect(obj, true) + '解析成功';
};

app.locals.headers = function(req, res) {
    return util.inspect(req.headers, true) +'解析成功动态视图助手'
}

2.在helper.js中

var express = require('express');
var router = express.Router();

router.get('/', function(req, res) {
    res.render('helper', {
        title: 'help',
        _req: req,
        _res: res
    });
});

module.exports = router;

3.在helper.ejs中:

<%= inspect.headers(_req, _res) %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant