我正在尝试在单文件组件中使用全局注册的组件(使用Vue.component),但我总是得到以下错误:
vue.common.js:2611[Vue warn]: Unknown custom element: <my-component> - did you register the component correctly?
例如:
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>
如果我在本地注册它,那么它就可以正常工作:
<template>
<div>
<my-component></my-component>
</div>
</template>
<script>
module.exports = {
name: 'home',
components: {
'my-component': require('./my-component.vue')
}
}
</script>