首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在不同的html或js文件中分离ractive脚本?

有没有办法在不同的html或js文件中分离ractive脚本?
EN

Stack Overflow用户
提问于 2015-10-27 03:35:40
回答 2查看 139关注 0票数 0

我的index.html文件中有很多脚本,其中包含了我所有的Ractive脚本。我想知道是否有一些方法来组织这一切,并将这些脚本放在不同的html或js文件中。

我的意思是:

代码语言:javascript
复制
//index.html
<script type="text/html" id="template-1">
...content...
</script>

<script type="text/html" id="template-2">
...content...
</script>

<script type="text/html" id="template-3">
...content...
</script>

以下是我想要实现的目标

代码语言:javascript
复制
//template1.html or js
<script type="text/html" id="template-1">
...content...
</script>

//template2.html or js
<script type="text/html" id="template-2">
...content...
</script>

//template3.html or js
<script type="text/html" id="template-3">
...content...
</script>

我尝试过这样做,但我得到了错误,因为我的ractive对象在我的index.html上,并且没有办法包含其他html文件。我相信其他人以前也有过这样的问题,这可能吗?

EN

回答 2

Stack Overflow用户

发布于 2015-10-27 06:18:58

您应该使用每个文件的components。这允许您将一个组件打包到一个文件、脚本、样式和标记中,同时保持它们之间的分离。为了使用组件,你需要使用available in just about every module management/bundling system out there的加载器。

票数 1
EN

Stack Overflow用户

发布于 2015-10-28 22:48:17

您可以使用php或其他服务器端脚本

代码语言:javascript
复制
<?php

include_once('a.html');

include_once('b.html');

include_once('c.html');

?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33354125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档