extend創建的是一個組件構造器,而不是一個具體的組件實例,最終還是要通過Vue.component注冊才可以使用
組件構造器相當於Vue.component()方法的第二個參數部分
const Loading = Vue.extend({
template: ``,
data () {
return {
hello: ''
}
}
})
// 注冊局部組件
Vue.component('loading', Loading)
組件構造器實例化后,傳入的data數據需要放在propsData中
new Loading({
propsData: {
hello: '你好'
}
}).$mount('#div')
$mount()方法表示將組件掛載,#div表示掛載到id為div的DOM上