首页 新闻 会员 周边

VueJS的X-Templates可以将模板写到其他文件吗

0
[已解决问题] 解决于 2017-05-18 13:03

各位好,实例代码如下

复制代码
<div id="watch-example">
        <hello-world></hello-world>
    </div>
    <script type="text/x-template" id="hello-world-template">
        <p>Hello World</p>
    </script>
    <script type="text/javascript">
        Vue.component("hello-world", {
            template: "#hello-world-template"
        });
        var vm = new Vue({
            el: "#watch-example"
        })
    </script>
复制代码

我想将组件做成公共组件,然后通过引用js的方式来进行模板注册。

但是,如果将Vue.component单独提取js文件,它的模板x-template,创建不了

请问我能否有办法把,这个模板单独提取到一个文件里面呢?

Pino晨的主页 Pino晨 | 菜鸟二级 | 园豆:203
提问于:2017-03-02 17:07
< >
分享
最佳答案
0

除了单文件组件,没有其他办法。结贴

Pino晨 | 菜鸟二级 |园豆:203 | 2017-03-03 09:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册