渲染PUG模板的一部分而不刷新页面 [英] Rendering a portion of a PUG template without refreshing page

查看:76
本文介绍了渲染PUG模板的一部分而不刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一个哈巴狗模板index.pug.我还制作了navbar.pug,footer.pug,sidenav.pug.这些文件包含在index.pug中. 对于服务器端,我使用的是node.js,express.js和socket.io.现在,我只想根据服务器响应更新navbar.pug文件.但是,当我尝试这样做时,我发现了一些解决方案.但是所有这些都刷新了整个索引页面. 有没有什么方法可以在不刷新整个页面的情况下帮助您更新网页的特定部分(在PUG中)? 预先感谢...

I have a pug template index.pug for my project. I have also made navbar.pug, footer.pug, sidenav.pug. These files are included in the index.pug. For server side I am using node.js, express.js and socket.io. Now I want to update only the navbar.pug file according to server response. But when I tried to do that I found some solution. But all of them refresh the full index page. Is there any method that can help to update an specific portion of the webpage(in PUG) without refreshing the whole page? Thanks in advance...

推荐答案

不,pug是仅服务器端的HTML处理器.因此,无法执行您在此处描述的操作-使哈巴狗处理更多操作意味着再次往返服务器以重新呈现页面.

No, pug is a server-side only HTML processor. As such there is no way to do what you describe here - to get pug to process more means another round trip to the server to re-render the page.

尽管从技术上讲,您可以使用普通的JavaScript来做到这一点,但您应该研究诸如jquery,React,Angular或Vue之类的客户端库来完成所需的工作.我们中的许多人都将pug与这些工具集结合使用来构建现代的Web应用程序,但是有了这些框架,pug成为了编写HTML的较快方法,并且不再是服务器端预处理器.

Although technically you could do this with plain JavaScript, you should look into a client-side library like jquery, React, Angular, or Vue to do what you want. A lot of us use pug in combination with those toolsets to build modern web apps, but with those frameworks pug becomes a quicker way to write HTML and is no longer a server-side pre-processor.

这篇关于渲染PUG模板的一部分而不刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆