Vue---全局组件和局部组件

注意:在全局/局部组件中如果含有data属性,那么它必须是一个返回Object的函数!!

1、注册全局组件

// 注册 Vue.component('my-component', { template: '
A custom component!
', //注意:这里虽然用的驼峰原则,但是会被解析成中划线原则(:my-message), //所以在给这个组件传递props的时候 需要这样写:my-message='你好啊'; props : ['myMessage'], data : function(p){ return { p : p++ }; } }) // 创建vue实例 new Vue({ el: '#example' })

2、局部组件

局部组件只在另一个实例/组件的作用域内存在。

//局部组件
var Child = {
  template: '
A custom component!
', data : function(p){ return { p : p++}; } } new Vue({ components: { // 将只在父模板可用 'my-component': Child } })

你可能感兴趣的:(Vue---全局组件和局部组件)