nestjs - Fastify 模式下 NestJS 动态模板渲染 - res.render 不是函数
问题描述
我觉得Model-View-Controller @ docs.nestjs.com没有涵盖这个用例 - 有“动态模板渲染”部分 + Fastify 但两者结合在一起似乎效果不佳。
我尝试了以下代码段:
import { Get, Res } from '@nestjs/common'
@Get()
index(@Res() res) {
if (isFoo()) {
return res.render('template1.html', {var1: 'foo'})
} else {
return res.render('template2.html', {var2: 'bar'})
}
}
它失败了
TypeError:res.render 不是函数
有什么办法可以解决吗?
为了清楚起见,我不使用的原因@Render
是因为我需要该操作中的条件逻辑。
解决方案
res.render()
是快递方式。对于 Fastify,您需要安装point-of-view
和使用res.view()
推荐阅读
- css - 将 alpha 蒙版添加到 SVG
- r - 用列表中的空格替换句点时出错
- android - 如何围绕 ImageView 对齐 TextView?图片应该在 textview 的右边
- python-3.x - 打印返回的 Zeep 对象的特定值
- android - 更改 Snackbar 样式
- c++ - 汇编x64 linux问题C ++中的模数
- sql - 使用 athena-express 的 Athena 查询不适用于 req.body 输入
- r - 如何在 r 中找到传单地图的 shapefile 数据的正确投影?
- mysql - 子查询使用 REPLACE 返回超过 1 行
- c# - 我无法获得在 Android 11 上管理外部存储的权限