如何在 pug.compile() 中使用 mixin

问题描述 投票:0回答:0

我想做这样的事情:

mixin table_row(event)
    tr 
        td=event.name
        td=event.type
        td=event.time
        td=event.venue
        td
            +dropdown(event.id)

script.
    const setEvents = (events) => {
        let tbody = document.getElementById('events-tbody')

        const compile = pug.compile(
            `each event in events` +'\n'+
            `   tr` +'\n'+
            `       +table_row(event)`
        )

        tbody.innerHTML = compile({events})
    }

单击按钮时,我调用了一个获取事件的 API。我想使用我已经在 .pug 文件中定义的

table_row
mixin 在表格中显示这些事件。

现在这段代码给出了一个错误,即

table_row
未定义。有没有办法让我在
pug.compile()
函数中传递这个mixin?

参考: https://pugjs.org/api/reference.html#pugcompilesource-options

javascript html pug
© www.soinside.com 2019 - 2024. All rights reserved.