是否可以将 mixin 参数绑定(bind)到 vue 实例?
我有这个 mixin 来渲染表格:
mixin table(header,data,type)
- var type = type || ""
table.table(class=type)
thead
tr
each head, i in header
th #{head}
tbody
each row,j in data
tr
each col,k in row
td #{col}
可以这样正常使用:
+table-striped(["#","First Name","Last Name","Username"],[["1","Mark","Otto","@mdo"],["2","Jacob","Thornton","@fat"],["3","Larry","the Bird","@twitter"]])
我的问题是是否可以从 vue 实例中获取 mixin 的“header”和“data”参数。
最佳答案
我认为您混淆了服务器端渲染(Pug 所做的)和客户端渲染(Vue.js 通常用来完成的事情)。您不能在创建 HTML 后动态“调用”mixins,因为这需要 Pug 渲染器在后台某处运行,监听此类请求。另见 this comment在官方 Pug 存储库上的相关 Github 问题上。
但是,您仍然可以将 Vue.js 与 Pug 结合使用,只是不是以这种方式。不要使用混合,考虑制作一个自定义的 Vue.js 组件来获取类似的输入,然后通过 some JS-pug-variable magic 注入(inject)想要的数据。 .
关于vue.js - 从 Vue 脚本中获取 Pug/Jade 混合参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46119842/