码迷,mamicode.com
首页 > 其他好文 > 详细

Vue 一个组件引用另一个组件

时间:2018-05-07 19:35:36      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:另一个   import   color   vue   imp   com   template   一个   ack   

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

方法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> 

 

Vue 一个组件引用另一个组件

标签:另一个   import   color   vue   imp   com   template   一个   ack   

原文地址:https://www.cnblogs.com/ming-os9/p/9004071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!