为什么“somefile.hbs”不允许使用把手/胡子在 html 上显示动态消息?

问题描述

背景:

  • 我正在尝试创建一个聊天应用程序,我需要在 HTML 页面(前端)上动态呈现消息。
  • 为此我使用了车把。
  • 但在后端,我也使用把手作为模板引擎来呈现应用程序的其他页面所以我必须将我的文件名保留为 chat.hbsunder get route res.render('chat')

聊天代码,js

const template=Handlebars.compile(messageTemplate)
const data={
    message:message
}
const html= template(data)

$messages.insertAdjacentHTML('beforeend',html)
})

HTML 代码

<script id="message-template" type="text/html">

    <div>
        <p>{{message}} </p>
    </div>
    
    </script>

在我将文件重命名为 chat.html 并将其位置从视图更改为公共目录之前,这不起作用。

但我必须使用 chat.hbs 并将此文件保存在视图目录中,因为这是我的应用程序呈现应用程序其他页面的方式,而且此聊天应用程序也是应用程序的一部分。 这有什么好转的?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)