Wie verwende ich globale VueJS 2-Komponenten in einzelnen Dateikomponenten?
Ich versuche eine global registrierte Komponente zu verwenden (mit Vue.component) innerhalb einer einzelnen Dateikomponente, aber ich erhalte immer
vue.common.js:2611[Vue warn]: Unknown custom element: <my-component> - did you register the component correctly?
Beispielsweise
main.js:
...
Vue.component('my-component', {
name: 'my-component',
template: '<div>A custom component!</div>'
})
...
home.vue:
<template>
<div>
<my-component></my-component>
</div>
</template>
<script>
module.exports = {
name: 'home'
}
</script>
Wenn ich es lokal registriere, funktioniert es OK:
<template>
<div>
<my-component></my-component>
</div>
</template>
<script>
module.exports = {
name: 'home',
components: {
'my-component': require('./my-component.vue')
}
}
</script>