【发布时间】:2017-03-12 22:17:57
【问题描述】:
我正在尝试在单个文件组件中使用全局注册的组件(带有 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>
【问题讨论】:
-
您需要在某处要求该组件,否则将无法下载。
-
@Elfayer 一切都在 Vueify 创建的包中,主组件在 main.js 文件中是必需的。
标签: javascript vue.js vue-component