0

我有一个 KOA 端点。我有一个quantify只能接受数字的参数,如何直接在 KOA 路由器中强制执行?

.put('/cart/:product/:quantity', async ctx => {
    quantity = ctx.params.quantity;
    ctx.body = 'my code here';
}
4

1 回答 1

1

使用这个正则表达式:

'/cart/:product/:quantity(\\d+)'

^ 匹配仅由数字组成的数量。\d+是正则表达式,但是您必须\为路由器添加另一个以将其转换为正确的正则表达式,因为路由是一个字符串。

于 2016-03-17T02:55:37.177 回答