【问题标题】:ejs tags causing errors inside the script tagejs标签导致脚本标签内的错误
【发布时间】:2019-09-13 16:03:28
【问题描述】:

我正在尝试在 ejs 模板的内部脚本标签中使用 ejs 标签。代码有效,但“vs code”仍然表示存在“问题”,“”是红色突出显示

 <form action="/posts/<%=post.id %>?_method=DELETE" method="POST">
      <button> delete </button>
    </form>

//internal script
    <script>
      var post = <%- JSON.stringify(post) %> ; 
      mapboxgl.accessToken = 'pk.eyJ1IjoibWlsZXMtYmxhcSIsImEiOiJjazBld3NxZjEwam0wM2V0aTV0MmlreDQxIn0.rEo1aSdtmy8RL-wX4Ni3AA';
    //setting up client side mapbox
      var map = new mapboxgl.Map({
        container: 'map',
        style: 'mapbox://styles/mapbox/light-v9',
        center: post.coordinates,
        zoom: 3
      });

【问题讨论】:

    标签: javascript node.js ejs


    【解决方案1】:

    你必须像这样修改post变量的声明,

    var post = <%= JSON.stringify(post) %> ; 
    

    【讨论】:

    • 实际上修复了它,问题是因为我在内部脚本中编写它,而我的 ejs 文件关联是“html”..所以我不得不将它添加到我的 settings.json“html. validate.scripts": false,".. 成功了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多