能不能自己写?能不能合并?
nest g decorator eee --flat
另一个问题 装饰器太多了,能不能合并成一个 ?
使用 applyDecorators
类似这样
import { applyDecorators, Get, UseGuards } from '@nestjs/common';
import { Aaa } from './aaa.decorator';
import { AaaGuard } from './aaa.guard';
export function Bbb(path, role) {
return applyDecorators(
Get(path),
Aaa(role),
UseGuards(AaaGuard)
)
}
也可以自定义参数装饰器
f 参数的值是就是 fff,也就是说参数装饰器的返回值就是参数的值
内部装饰器也可以写 比如实现下 @Query 装饰器
知道了如何自定义方法和参数的装饰器,那 class 的装饰器能不能写 ?
当然也可以放多个 用applyDecorators