美文网首页
组件嵌套

组件嵌套

作者: tutututudou | 来源:发表于2022-07-15 14:00 被阅读0次

app 作为顶级组件

  <div class="root"></div>
  <script>
    // 组件student 简写模式
    const student = {
      template:`<h1>高高</h1>`
    }
    // 组件shool,完整写法,嵌套了student这个组件
    const shool = Vue.extend({
      template:`<div><h1>理工</h1>
        <student></student>
      </div>`,// 在模板中写上student组件,组件可以嵌套另外一个组件
      components:{
        student
      }
    })
    //app这个组件作为顶级组件,把所有的组件都放到这里,然后再百这个组件注册到root这个容器中
    const app = Vue.extend({
      template:`<div>
        <shool></shool>
      </div>`,// 在模板中写上student组件,组件可以嵌套另外一个组件
      components:{
        shool
      }
    })
    //哪个组件容器服务
    new Vue({
      el:'.root',
      template:'<app></app>',
      components:{app}
      
    })
  </script>
组件嵌套.PNG
  • APP嵌套了shool,shool嵌套了student

相关文章

网友评论

      本文标题:组件嵌套

      本文链接:https://www.haomeiwen.com/subject/nfcerrtx.html