Vue.component使用注意事项

Vue.component使用的时候并不是随便使用的,我们要遵循一个原则:

要在初始化根实例之前注册组件,例如;
 
  
 
  


 
  
// 注册
Vue.component('my-component', {
  template: '
A custom component!
' }) // 创建根实例 new Vue({ el: '#example' })

渲染结果为:
 
  
A custom component!

有个先后,特别是我们用webpack搭建的模板,毕竟main.js就创建了根实例,需要特别注意

你可能感兴趣的:(Vue.component使用注意事项)