I am trying to use a search-bar component
inside my home.vue
component but I can't figure out why its not working.
Folder structure
App.vue
components
home.vue
query.vue
common
HeaderBar.vue
SideBar.vue
SearchBar.vue
App.vue
script
import HeaderBar from './components/common/HeaderBar'
import SideBar from './components/common/SideBar'
export default {
name: 'App',
components: {
HeaderBar,
SideBar
},
html
<template>
<div id="app">
<HeaderBar></HeaderBar>
<SideBar></SideBar>
<main class="view">
<router-view></router-view>
</main>
</div>
</template>
This above works just fine.
Home.vue
script
import SearchBar from './common/SearchBar'
export default {
name: 'Home',
components: SearchBar
}
html
<template>
<section class="home">
<div class="hero-content">
<h1>Hello World</h1>
<SearchBar></SearchBar>
</div>
</section>
</template>
I get those errors:
[Vue warn]: Invalid component name: "_compiled". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.
[Vue warn]: Invalid component name: "__file". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.
[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> <Home> at src\components\Home.vue <App> at src\App.vue <Root>
main.js
somewhere in your project where you specify the names of all the components you are using. It seems like Vue can't recognize what component you want to use. It should be something like this:Vue.component('app-searchbar', SearchBar);
See here: vuejs.org/v2/guide/components-registration.html – Eugenioimport SearchBar from './components/common/SearchBar'
and thenVue.component('app-search', SearchBar);
. So now its registered it globally and I can remove theimport
andcomponents: {}
in myapp.vue
? – user9389851