zoukankan      html  css  js  c++  java
  • Vue 一个组件引用另一个组件

    有些时候需要这么做,比如,我想在首页加载轮播组件,但是又不想全局注册(因为不是每个页面都需要轮播功能)

    方法1:

     1 <template>  
     2     <div>  
     3         <!-- 3.在template中就可以直接使用了 -->  
     4         <testComponent></testComponent>  
     5     </div>  
     6 </template>  
     7   
     8 <script>  
     9     //1.先使用import导入你要在该组件中使用的子组件  
    10     import testComponent from './testComponent.vue'  
    11     export default {  
    12         //2.然后,在components中写入子组件  
    13         components: {testComponent},  
    14         methods: {},  
    15     }  
    16 </script>  
    17   
    18 <style></style>  

    方法2:

     1 <template>  
     2     <div>  
     3         <!-- 2.在template中使用 -->  
     4         <testComponent></testComponent>  
     5     </div>  
     6 </template>  
     7   
     8 <script>  
     9     export default {  
    10         //1.直接在components中写入子组件  
    11         components: {  
    12             testComponent:require('./testComponent.vue').default  
    13         },  
    14         methods: {},  
    15     }  
    16 </script>  
    17   
    18 <style></style> 
  • 相关阅读:
    C 字符串
    C 函数指针、回调函数
    C 指针
    C 数组、枚举类型enum
    C 函数声明、函数参数
    C 内置函数
    C 流程控制
    C 储存类与运算符
    C变量和常量
    名词解释
  • 原文地址:https://www.cnblogs.com/ming-os9/p/9004071.html
Copyright © 2011-2022 走看看