Connect.js methodOverride有什么作用?

Ran*_*lue 116 node.js connect.js

Connect.js 非常简洁的文档methodOverride

提供虚拟HTTP方法支持.

那是什么意思?在明显的谷歌搜索不到有帮助的.为什么methodOverride有用?

ale*_*lex 147

  • 如果要模拟DELETEPUT,methodOverride是该.
  • 如果您将_method post参数设置传递给'delete''put',那么您可以在Express中使用app.deleteand app.put而不是一直使用app.post(因此更具描述性,详细):

后端:

// the app
app.put('/users/:id', function (req, res, next) {
  // edit your user here
});
Run Code Online (Sandbox Code Playgroud)

客户逻辑:

// client side must be..
<form> ...
  <input type="hidden" name="_method" value="put" />
</form>
Run Code Online (Sandbox Code Playgroud)

  • 来源应该是[http://www.senchalabs.org/connect/methodOverride.html](http://www.senchalabs.org/connect/methodOverride.html) (5认同)