【问题标题】:Unexpected token == while compiling ejs编译 ejs 时出现意外的令牌 ==
【发布时间】:2021-10-13 00:02:53
【问题描述】:

我的 ejs 部分文件中有一个 if/else if 语句。我只想在我的主文件中包含样式部分。 这是我的代码:

<% if(someVariable == "style"){ %>
    .some-css{
    bottom: -100px;
    visibility: visible;
}
<% } %>
<% else if(someVariable == "code") { %>
    <div class="some-css" > 
some code
</div>
<% } %>

在我的主文件中,我包含了这样的样式:&lt;%- include('partials/nameofFile.ejs',{ someVariable == "style" }) %&gt; 我得到了错误:

编译 ejs 时意外 ==。

【问题讨论】:

    标签: node.js express ejs


    【解决方案1】:

    问题是当您尝试包含一个单独的文件时,您是在一个对象中编写普通的 JavaScript,而该对象只接受 JSON 值。

    改变你的:

    <%- include('partials/nameofFile.ejs', { someVariable == "style" }) %>
    

    收件人:

    <%- include('partials/nameofFile.ejs', { someVariable: "style" }) %>
    

    【讨论】:

    • 当我再次运行它时,错误现在从意外令牌 == 变为意外令牌其他
    • @tellmeOberlin 您的问题中没有包含完整的代码,因此我无法为您提供帮助。由于这个答案已经解决了问题,请点击帖子旁边的绿色勾号将其标记为正确的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多