Vue.js——6.创建组件

Vue组件
组件就是为了拆分Vue实例的代码量,能够不同的功能定义不同的组件
创建组件的方法
1.
// 创建组件
let com1=Vue.extend({
template:'<h1>hellow</h1>'//必须加标签名称
})
Vue.component('myCon1',com1)
引用 <my-con1></my-con1>
//或者不用驼峰

第二种
Vue.component('myCon1',{
template:'<h1>hellow</h1>'
})

第3种
Vue.component('myCon1',{
template:'#tmp1'
})
在app外面
<template id="tmp1">
<h1>hollow</h1>
</template>

猜你喜欢

转载自www.cnblogs.com/ruogu/p/10945678.html