我完全迷失了; 我正在使用NodeJS来获取JSON,我需要将变量传递给我的页面并让JavaScript使用数据.
app.get('/test', function(req, res) {
    res.render('testPage', {
        myVar: 'My Data'
    });
这是我的Express代码(非常简单,用于测试目的); 现在使用JADE我想收集这些我知道要在页面上呈现的数据
p= myVar
但是我需要能够在JavaScript中收集这些数据(如果可能的话,在.js文件中),但现在只是在Alert框中显示变量我试过了
alert(#{myVar})
还有许多其他人如果有人可以帮助我们非常感激
我想基于它的api实现谷歌地图.我想基于坐标添加路径.因此,我从我的模型中获取坐标,并希望迭代对象以使用此点填充地图.在我的玉模板中,我包含这样的api js代码:
script(type='text/javascript')
    function initialize() {
      var myLatLng = new google.maps.LatLng(0, -180);
      var myOptions = {
        zoom: 3,
        center: myLatLng,
        mapTypeId: google.maps.MapTypeId.TERRAIN
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
      var flightPlanCoordinates = [
       - if (typeof(pins) != null)
           - var.pins.forEach(function(pin) {
                new google.maps.LatLng(pin.latitude, pin.longitude),
           - })
           new google.maps.LatLng(0,0)
      ];
      var flightPath = new google.maps.Polyline({
        path: flightPlanCoordinates,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
      });
      flightPath.setMap(map);
    }
div#map_canvas(style='height: 500px; background-color: #990000;')
问题是:jade渲染这个片段
var flightPlanCoordinates = [
       - if (typeof(pins) != null)
           - …是否可以将 mixin 参数绑定到 vue 实例?
我有这个 mixin 来渲染表格:
mixin table(header,data,type)
- var type = type || ""
table.table(class=type)
    thead
        tr
            each head, i in header
                th #{head}
    tbody
        each row,j in data
            tr
                each col,k in row
                    td #{col}
可以像这样正常使用:
+table-striped(["#","First Name","Last Name","Username"],[["1","Mark","Otto","@mdo"],["2","Jacob","Thornton","@fat"],["3","Larry","the Bird","@twitter"]])
我的问题是是否可以从 vue 实例中获取 mixin 的“header”和“data”参数。
我的index.pug文件中有此代码
doctype html
html
  head
    title= title
  body
    script(src=`${source}`)
    script.
      for (var event of events){
        VClient.Event.subscribe(event, createDiv);
      } 
这是我将变量从 Express 传递给 pug 的方式。
var express = require('express');
var app = express();
app.set('view engine', 'pug')
app.get('/', function(req, res){
    var id = req.query.id || 23717;
    var source = `https://some.source.url/${id}.js`;
    res.render('index',
    {title: 'Preview Embed', source: source, events:["AD_START","AD_COMPLETE"]});
});
app.listen(5000);
两者title并source使其进入 pug 文件。但不是events:
Uncaught ReferenceError: events is not defined
如何在script.块内正确传递变量?