我不知道“res.render”是否可以使用两次。错误是:
C:\ReactVap\vapinto\src\controller\LaunchController.js:45
return res.render('index', { launch })
^
TypeError: Cannot read property 'render' of undefined
我有这个:
routes.get('/index', (req, res) => {
if (req.isAuthenticated()) {
// console.log(req.user)
res.render('index', LaunchController.index, {user:req.user});
} else {
res.render('login', {
title: 'Home',
user: req.user,
message: res.locals.message,
});
}
}
)
在控制器中,我有:
async index(req,res) {
const lancamentos = await Launch.get()
let saldoAnterior = 0;
let launch = lancamentos.map((item) => {
// Intl.NumberFormat('pt-br', {style: 'currency', currency: 'BRL'}).format(money)
// .toLocaleString('pt-br',{style: 'currency', currency: 'BRL'})
// .toFixed(2).replace('.', ',')
const dataFormatada = LaunchUtils.dataFormatada(item)
const receita = LaunchUtils.receita(item)
const despesa = LaunchUtils.despesa(item)
const saldoAtual = receita - despesa
const saldo = saldoAnterior + saldoAtual;
saldoAnterior = saldo;
return{
...item,
dataFormatada,
receita,
despesa,
saldo
}
})
const month = '';
if(month > 0) {
launch = launch.filter(item => {
const month = req.query.month;
const data = new Date(item.data);
const dataString = (data.getFullYear() + "-" + ((data.getMonth() + 1)) + "-" + (data.getDate() ))
return LaunchUtils.formatDate(dataString).getMonth() == month
})
}
return res.render('index', { launch })
}
1条答案
按热度按时间yacmzcpb1#
可以在公共文件中进行渲染
例子:
无论您想在何处使用渲染,请导入该渲染并将其与适用的配置一起使用