// 定義一個(gè) Child 組件
var Child = {
template: '<div>A custom component!</div>'
}
// 新的 Vue 實(shí)例
new Vue({
el: '#example'
// 在實(shí)例中使用 components 屬性注冊(cè)需要用到的組件
components: {
// 使用 key: value 的形式注冊(cè) Child 組件,并命名為 my-component
// 則 <my-component> 只在這個(gè)實(shí)例中可用
'my-component': Child
}
})
// 使用
<div id="example">
<my-component></my-component>
</div>
參考:組件