如何在Pug中删除一段时间后的错误警报



伙计们。我还在学习express,我正在使用Pug在浏览器中查看我的元素。当客户试图在填写所有信息之前发送推荐信时,我会显示错误警报。问题是这些警报会一直显示在屏幕上,不会消失。我想让它们在几秒钟后消失。

这是我用来将错误发送到commissiones.pug文件的代码。

const errores = [];
if(name.trim() === ''){
errores.push({message : 'The name is empty'});
}

if(mail.trim() === ''){
errores.push({message : 'The mail is empty'});
}

if(message.trim() === ''){
errores.push({message  : 'The message is empty'});
}

* if(errores.length > 0){
//consult the testimonials that already exis
const testimoniales = await Testimonial.findAll();
//show the view with errors
res.render('testimoniales', {
page: 'Testimoniales', 
errores,
name, 
main,
message,
testimoniales
});*
}else{
//Save in the DATABASE 
try {
await Testimonial.create({
name, 
mail,
message
});
res.redirect('/testimoniales');
} catch (error) {
console.log(error);
}
}

这是显示我的感言.pug文件中错误的代码。

if(errores)
each error in errores
.alert.col.alert-danger.text-center= error.mensaje

所以,我只想在3或5秒后消除警报。

您需要一些客户端Javascript。

类似于:

if (errores)
#errors
each error in errores
.alert.col.alert-danger.text-center=error.mensaje

并添加,可能在</body>之后,:

if (errores)
script.
setTimeout(()=>
document.getElementById("errors").style.display="none", 5000);

相关内容

最新更新