【问题标题】:Render a mixin Pug templateRender a mixin Pug template
【发布时间】:2021-08-10 04:41:42
【问题描述】:

我想在 Ajax 调用之后呈现一个模板。

我的代码是:

index.pug
  include form.pug
  +list('style')

form.pug
mixin list(style)
   p(class=style) my form

我想在点击按钮后添加form.pug,所以

我的 ajax 调用是:

$.ajax({
        url: "/myroute",
        method: "POST",
        data: msgObj,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        datatype: "json",
        success: function (msg) {
            div.prepend(msg.template)
        },
    });

/myroute(服务器节点)是:

const pug = require('pug');
var template = pug.renderFile('Path/form.pug');
res.send({"template":template,"style":"new_style"});

点击按钮后我的模板没有出现。 在我删除 mixin 时,一切正常,但我需要在模板生成期间传递一个参数

【问题讨论】:

    标签: node.js pug template-engine


    【解决方案1】:

    在页面某处调用 mixin,在 AJAX 调用后在 DOM 中选择它,并在添加之前填充所需的值。

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      相关资源
      最近更新 更多