在app.js中配置好用到的东西:
app.use(express.static(path.join(__dirname, 'build'))); app.use(express.favicon()); app.use(express.logger('dev')); app.use(require('connect').bodyParser()); //post方法传参必须配置的 app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) app.use(express.methodOverride()); app.use(express.cookieParser('your secret here')); app.use(express.session()); app.use(app.router); //must be the last thing you call
开始时把app.use(app.router);放在了前面,结果无论怎样参数都传不过去,在网上查到结果:. You need to use app.use(express.bodyParser())
before app.use(app.router)
. In fact, app.use(app.router)
should be the last thing you call.