vue创建全局组件

创建组件使用Vue.component()方法,它是创建的全局组件

  • 参数1表示组件名字
  • 参数2表示组件配置项
    <div id="app">
      <!-- 2. 使用组件,像html标签一样 -->
      <index></index>
      <index-b></index-b>
    </div>
    <script>
      Vue.component('index', {
        // template属性指定组件模板
        template: '<div>这是首页<index-b></index-b></div>'
      })

      // 注意组件命名如果使用驼峰命名法,上面在页面中使用的时候就需要改成连字符⭐
      Vue.component('indexB', {
        // template属性指定组件模板,模板只能有一个根节点⭐
        template: '<div>这是首页B</div>'
      })
      var vm = new Vue({
        el: '#app',
        data: {

        }
      })
   </script>
posted @ 2019-03-12 09:46  木石天涯  阅读(1501)  评论(0编辑  收藏  举报