【问题标题】:how to pass script src in to jade template如何将脚本 src 传递给玉模板
【发布时间】:2015-06-02 01:33:25
【问题描述】:

我有一个玉模板,我想将一个变量作为脚本 src 传递,因为在不同的路线上脚本会改变。我如何在 Jade and Express 中做到这一点?

doctype html
html
  body
    #app!= html

  script(src={bundle})

在脚本 src 中传入我想要的 bundle 变量

var html = React.renderToString(node)
var bundle = '/public/js/bundle.js'

res.render('layout', { html: html, bundle: bundle })

【问题讨论】:

    标签: javascript node.js express pug


    【解决方案1】:

    看起来我可以自己回答这个问题,在question的帮助下

    正如它所说,# 用于转义数据,! 用于原始数据。

    doctype html
    html
      body
        #app!= html
    
      script(src='#{bundle}')
    

    【讨论】:

      【解决方案2】:

      只需删除 #! 和引号即可。这对我来说很好:

        doctype html
        block vars
          - var html = React.renderToString(node)
          - var bundle = '/public/js/bundle.js'
        html
          body
            #app!= html
      
            script(src=bundle)
      

      【讨论】:

        猜你喜欢
        • 2019-11-15
        • 2015-08-24
        • 2012-10-09
        • 1970-01-01
        • 2012-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-20
        相关资源
        最近更新 更多