全局组件
//DOM
<tagname></tagname>
//JS
Vue.component('tagname',
{template:'html结构'}
);
局部组件
只有header才能用的组件
var header = new Vue({
el: '#header',
//子组件必须声明后使用,不然不能起效
components: {
'组件名': 组件object,
},
});
组件之间的信息传递
父传子
//组件
Vue.component('child', {
// 声明 props
props: {
message:{
type:string,//数据类型
required:true,//必填
default:"liu"//默认值
}
},
data(){
return{
}
},
template: '<span>{{ message }}</span>'
})
//父级
<child message="传递内容"></todo-item>