javascript - vue.js组件问题

查看:73
本文介绍了javascript - vue.js组件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

<div id="app2">
        {{message2}}
        <parent></parent>
    </div>
    <script>
        var child2 = Vue.extend({
            template:'<p>this is child template</p>'
        })
        Vue.component('parent' , {
            template:'<p>this is parent template</p><child1></child1>',
            component:{
                "child1":child2
            }
        })  
        var vm2 = new Vue({
            el:"#app2",
            data: {
                message2 : "hello app2!"
            }
        })
        </script>
        

以上代码出现报错

求大神告知这为什么,应该如何修改,使得子组件里可以嵌套孙组件。

解决方案

  1. 组件的template只能有一个祖先级节点

  2. 局部注册组件使用components而不是component

这篇关于javascript - vue.js组件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆