vue中的组件化开发

image

image

image

image

全局注册:

Vue.component('my-component',componentObj)

局部注册:

components:{
myPartComponent:componentObjFather
}
注意:注册时如果写驼峰 使用标签时要将有驼峰处换成'-',如果不写驼峰可以这样写('my-part-component':componentObj)

vue2.x语法糖注册

正常在注册之前需要先进行下面这一步Vue.extend
const componentObjFather =  Vue.extend({
//嵌套了子组件 (应用模版分离写法 通过id指向模版)
template:'#myTemplate'
})
但在vue2.x之后有了语法糖注册组件于是可以省略了这一步
直接将模版对象拿来注册

猜你喜欢

转载自www.cnblogs.com/chujunqiao/p/11625478.html