【问题标题】:Read Spring ModelAndView objects in Pug在 Pug 中读取 Spring ModelAndView 对象
【发布时间】:2017-07-26 18:18:59
【问题描述】:

我的前端应用程序使用 Pug 生成 index 页面。

作为一个 Vue.js 应用程序,它可以从 Java(生产目的)或 Node(开发目的)提供服务

开发

index.pug 中的变量通过运行以下命令注入:

pug -P -s -O ./variables.js -o ./ index.pug

variables.js 类似于:

variables = {
  value: 'something'
}

index.pug 中的变量可以这样读取:

if variables.value == 'something'
  //show some tags ecc...

一切正常。

生产

为了渲染 index.pug 服务器端,我使用jade4j

在索引控制器中,我执行以下操作:

@RequestMapping(value = "/index.htm")
public ModelAndView indexView(...) {
   ... other code here...
   ModelAndView mav = new ModelAndView("index");
   mav.addObject("value", "something");
   return mav;
}

value 可以通过'#{value}' 语法在script. 标记中读取,如下例所示:

script.
   console.log('#{value}') // prints "something"

如何在上述开发场景中读取value

【问题讨论】:

    标签: spring-mvc pug jade4j


    【解决方案1】:

    This给了我答案。

    毕竟这很简单...我从未尝试过的东西,因为觉得它太假了。

    只需在“Pug 代码”中使用 #{value} 而不使用 '',否则使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 2018-04-06
      • 2014-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多