ejs标记在script标记内导致错误

时间:2019-09-12 09:30:34

标签: javascript node.js ejs

我正在尝试在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
      });

1 个答案:

答案 0 :(得分:0)

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

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