是否可以将 mixin 参数绑定到 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}
Run Code Online (Sandbox Code Playgroud)
可以像这样正常使用:
+table-striped(["#","First Name","Last Name","Username"],[["1","Mark","Otto","@mdo"],["2","Jacob","Thornton","@fat"],["3","Larry","the Bird","@twitter"]])
Run Code Online (Sandbox Code Playgroud)
我的问题是是否可以从 vue 实例中获取 mixin 的“header”和“data”参数。
假设我有一个段落,其中包含从某些数据库中获取的一些文本:
<p>
{{ text }}
</p>
Run Code Online (Sandbox Code Playgroud)
但是,此文本可能包含对我的应用中其他页面的一些引用:
Sample text [reference] sample text
Run Code Online (Sandbox Code Playgroud)
因此,我希望这些参考可以变成指向所述页面的链接:
<p>
Sample text <a href="/path/to/reference"> reference </a> sample text
</p>
Run Code Online (Sandbox Code Playgroud)
我尝试在脚本中使用replace函数,如下所示:
text.replace(/\[(.+)\]/,"<a href='/path/to/$1'>$1</a>");
Run Code Online (Sandbox Code Playgroud)
但是所有字符都被转义,导致锚html代码显示在页面上。
有没有一种方法可以阻止字符转义,或者还有另一种方法可以将文本中间的[references]转换为指向另一页的有效链接?