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

  • 参数1表示组件名字
  • 参数2表示组件配置项
    <div >
      <!-- 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>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2021-07-04
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2022-01-04
  • 2023-03-19
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案