我想知道是否可以这样做:
<todo>
<div class="greetings">Hello, world!</div>
<script src="/path/to/my/file.js"></script>
</todo>
标签将保留 View (html) 而 js 代码保留在不同的文件中:
- todo.tag (html/css)
- 待办事项
最佳答案
提供 mixin
的替代方案解决方案,这是从逻辑中分离标记的另一种方法。
看看this Plunker (我的一位同事写了这个)。关键部分是您引用标记函数的方式。 <script>todoTag.call(this, this.opts);</script>
.在这种情况下,todoTag
是一个全局函数。但是没有什么能阻止您使用命名空间来发挥作用或使用某种形式的模块加载。
来自 plunker:
todo.tag.html:
<todo>
<!-- your markup -->
<script>todoTag.call(this, this.opts);</script>
</todo>
todo.tag.js:
function todoTag(opts) {
// your logic
}
关于javascript - 是否可以将 javascript 代码与 Riot Js 中的标记文件分开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34756866/