2017-09-23 117 views
2

我試圖用其它成分(App.vue)一VUE成分(Global.vue),但使用VUE組件

無法裝載組件:模板或呈現功能不定義爲

錯誤。

Global.vue

<template> 
    <div class="global-view"> 
    <p>Global </p> 
    </div> 
</template> 

<script> 
export default { 
    name: 'global' 
} 
</script> 

App.vue

<template> 
    <div id="app"> 
    <global></global> 
    <router-view></router-view> 
    </div> 
</template> 

<script> 
export default { 
    name: 'app' 
} 
</script> 

main.js

import Vue from 'vue' 
import App from './App' 
import router from './router' 

Vue.component('global', require('./components/Global')) 

Vue.config.productionTip = false 

new Vue({ 
    el: '#app', 
    router, 
    template: '<App/>', 
    components: { App } 
}) 
+0

看到這個https://github.com/sagalbot/vue-select/issues/127 - 也許是要求聲明會產生問題,Johnathan建議使用import來代替。 –

+0

@RichardMatsen是啊,進口作品 – ramazan793

回答

1

你需要即時通訊端口要在使用它的組件文件中的組成部分。從「./components/Global」

從那裏

`進口全球您需要添加一個新的密鑰您的組件選項,將裏面的「註冊「組件。

這就是你希望你的應用程序組件看起來像。

<template> 
    <div id="app"> 
    <global></global> 
    <router-view></router-view> 
    </div> 
</template> 

<script> 
import Global from './components/Global 

export default { 
    name: 'app' 
    components: { 
    'global': Global, 
    } 
} 
</script> 

<global></global>應該能夠在這一點上呈現。

+0

OP已經在全球範圍內使用Vue.component展示組件。 – Bert

+1

@Bert:OP仍然需要通過將'new Vue'實例添加到'components'對象來註冊該組件。 –

+0

不,他沒有,當它在全球範圍內註冊時。 – Bert

1

我用來代替需要(在main.js)進口和它的作品對我來說:

import Global from './components/Global.vue 
Vue.component('global', Global)`