公共组件创建的三种方式和一种私有化组件创建方式(驼峰式写法)

组件的一些注意事项,当组件名采用了驼峰式写法式,组件标签需要在两个字之间加上分隔号。第一种组件写法有实例。

1.

    <div id="app">
<my-com></my-com>
</div>
Vue.component('myCom',Vue.extend({
template:'<h3>hello chp</h3>'
}))

var app = new Vue({
el:'#app',
data:{},
methods:{}
})

2.
    <div id="app">
<mycom></mycom>
</div>

Vue.component('mycom',{
template:'<h3>hello chp</h3>'
})
   var app = new Vue({
el:'#app',
data:{},
methods:{}
})

 3.

<div id="app">
<mycom></mycom>
</div>

<template id="tmp">
<div>
<h2>hello chp</h2>
</div>
</template>
Vue.component('mycom',{
template:'#tmp'
})
   var app = new Vue({
el:'#app',
data:{},
methods:{}
})

4.定义私有化组件
<div id="app">
<Login></login>
</div>

<template id="tmp">
<div>
<h2>hello chp</h2>
</div>
</template>
   var app = new Vue({
el:'#app',
data:{},
methods:{},
components:{
login:{template:'#tmp'
}
})
posted @ 2019-09-12 09:16  normalboy(NB)  阅读(236)  评论(0)    收藏  举报