鍍金池/ 問(wèn)答/HTML/ Vue組件嵌套,子組件不顯示

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.

回答
編輯回答
半心人

你在my-header組件里面只是注冊(cè)了my-top組件卻并沒有進(jìn)行調(diào)用。將my-header的字符串模板改寫為

'<h3> this is a parent <my-top></my-top></h3>'
2018年1月3日 21:08
編輯回答
囍槑

很好奇,最終只能顯示this is a parent.是怎么顯示的,你都沒有根template,也沒有調(diào)用my-header是怎么顯示的,你是在html里寫了my-header

你只是注冊(cè)了my-top組件,你并沒有在my-headertemplate里調(diào)用啊

2018年1月2日 01:22