鍍金池/ 問答/HTML/ Vue多層組件通信的一個小例子

Vue多層組件通信的一個小例子

如下面代碼,哪里錯了,運行之后瀏覽器里圖片和文字沒有加載出來

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多層組件通信</title>
</head>
<body>
    <div id="app">
        <my-parent :imgtitle='title' :imgsrc='img'></my-parent>
    </div>

    <template id="my_img">
        <img :src="imgsrc" width="200">
    </template>

    <template id="my_title">
        <h2>{{title}}</h2>
    </template>

    <template id="my_parent">
        <div>
            <child1 :imgsrc="imgsrc"></child1>
            <child2 :title="imgtitle"></child2>
        </div>
    </template>

        <script src="js/vue.min.js"></script>
        <script>
            //1.子組件的實例
            let Child1 = Vue.extend({
                template:'#my_img',
                props:['imgsrc']
            });
            let Child2 = Vue.extend({
                template:'#my_title',
                props:['title']
            });
            //注冊父組件
            Vue.component('my-parent',{
                props:['imgtitle','imgsrc'],
                compoents:{
                    'child1':Child1,
                    'child2':Child2
                },
                template:'#my_parent'
            });
            new Vue({
                el:'#app',
                data:{
                    title:'我很帥',
                    img:'img/01.jpg'
                }
            });
        </script>
</body>
</html>
回答
編輯回答
冷溫柔
  //注冊父組件
            Vue.component('my-parent',{
                props:['imgtitle','imgsrc'],
                compoents:{
                    'child1':Child1,
                    'child2':Child2
                },
                template:'#my_parent'
            });

compoents --> components

2017年3月15日 08:04