我正在尝试在单个文件组件中使用全局注册的组件(带有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>