局部组件两种创建方法
2018-08-10 本文已影响0人
持续5年输出bug
vue中,组件有局部注册和全局注册两种方式,全局注册的组件即使不再使用,但还是会被包含到最终构建的结果中。
第一种:先定义该组件,再在components 中定义要使用的组件
Var componentName={
template: “ ”
};
New Vue ({
el:” #nountpointsName”,
components:{
“componentname”:cmponentName
})
如下:

第二种:直接定义
new Vue ({
el:” #nountpointsName”,
components:{
“componentName”:{
template: “ ”
}
})
如下图

但是局部组件是不可以直接用在它自身的子组件中的,需要通过在子组件中components 选项里定义才可以使用。
var componentB = {
components: {
'component-a': componentA
},
}