javascript变量到jade模板中-服务器端

标签 javascript node.js express pug

我在使用 Jade 和 express 时遇到了一些问题。这是 serder 端:

router.get('/login', function (req, res) {
   res.status(200)
   res.render('login',{title:'login'})
   res.end()
});

这是我的 Jade :

doctype html
html(lang='en')
  head

    meta(charset='UTF-8')
    meta(name='viewport', content='width=device-width')
    title= #{title}
    block css
      link(rel='stylesheet', href='/css/style.css')
    block js
        //script(src='../public/js/')

        script(src='http://localhost:35729/livereload.js')
  body
    block content

当然,这些是我的错误:

  > 7|     title= #{title}
    8|     block css
    9|       link(rel='stylesheet', href='/css/style.css')
    10|     block js

Unexpected token ILLEGAL
    at Function (native)
    at assertExpression (/Users/VeaVictis/iGym/node_modules/jade/lib/lexer.js:30:3)
    at Object.Lexer.code (/Users/VeaVictis/iGym/node_modules/jade/lib/lexer.js:584:23)

还有更多,但我认为它们没有用。预先感谢大家。我借此机会祝您圣诞节快乐

最佳答案

尝试删除标题后的 = 号

应该是

title #{title}

关于javascript变量到jade模板中-服务器端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34349783/

相关文章:

node.js - 表达 js 4 如何在不渲染任何 View /css 的情况下提供 json 结果

node.js - Webpack 外部不可缓存

node.js - Mongoose FindOne 方法始终返回 'null'

javascript - 您可以向有状态组件传递一个在 componentDidMount() 内部运行的函数吗?

javascript - 转到 Javascript 中的随机页面

javascript - redux-form 格式输入仅 onBlur

javascript - document.open()语句自动滚动页面

node.js - socket.io 忽略 url 路径似乎会导致轮询 GET 404 错误

node.js - 如何在 Node.js 中创建绝对链接?

node.js - Passport.js - 是否可以将参数传递到路由器验证功能中?