Vue组件嵌套,子组件不显示

import Vue from 'vue'


new Vue({
    el: '#app',
    data: {
    },
    components: {
        "my-header" : {
            template: '<h3> this is a parent </h3>',
            components:{
                "my-top":{
                    template:'<p>this is a child</p>'
                }
            }
        }
    }
});



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>exprice</title>
</head>
<body>
<div id="app">
    <my-header>
    </my-header>
</div>
<!-- built files will be auto injected -->
</body>
</html>



最终只能显示 this is a parent.

阅读 9.2k
2 个回答

你在my-header组件里面只是注册了my-top组件却并没有进行调用。将my-header的字符串模板改写为

'<h3> this is a parent <my-top></my-top></h3>'

很好奇,最终只能显示this is a parent.是怎么显示的,你都没有根template,也没有调用my-header是怎么显示的,你是在html里写了my-header

你只是注册了my-top组件,你并没有在my-headertemplate里调用啊

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题