1.1 组件注册 vue shop

来源:互联网 发布:木村秋则 知乎 编辑:程序博客网 时间:2024/05/20 02:26

<div id="app"></div>   //最后替换成 <p>ni hao</p>new Vue({el:"app",template:'<p>ni{{hao}}</p>',data:{hao:'hao'}})一、全局组件注册<div id="app">  <my-header></my-header></div>Vue.component('my-header',{  template:'<p>this is my header</p>'});二、局部组件注册<div id="app">      <my-header></my-header></div>var Child={  template:'<p>子组件子组件</p>'};new Vue({  el:'#app',  router,  data:{    word:'hello worlds2'  },  components:{    'my-header':Child  }});三、组件中注册组件var myChild={  template:'<p>子组件中的子组件</p>',};var Child={  template:'<p>子组件子组件<my-header-child></my-header-child></p>',  components:{    'my-header-child':myChild  }};new Vue({  el:'#app',  router,  data:{    word:'hello worlds2'  },  components:{    'my-header':Child  }});


原创粉丝点击