I have fresh Rails 6 app with Vue.js
app/javascript/app.vue:
<template>
<div id="app">
<p>I am App component</p>
<list></list>
</div>
</template>
<script>
import list from './list.vue'
export default {
name: 'App',
data: function () {
return {
message: "Hello Vue!"
}
},
components: {
list
}
}
<style scoped>
p {
font-size: 2em;
text-align: center;
}
</style>
And app/javascript/list.vue component:
<template>
<div>
I am List Component
</div>
</template>
<script>
export default {
name: 'list',
data: function () {
return {
posts: []
}
}
}
</script>
And app/javascript/packs/hello_vue.js
import Vue from 'vue'
import App from '../app.vue'
document.addEventListener('DOMContentLoaded', () => {
const app = new Vue({
render: h => h(App)
}).$mount()
document.body.appendChild(app.$el)
console.log(app)
})
But in browser I get error
vue.runtime.esm.js:638 [Vue warn]: Unknown custom element: <list> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> <App> at app/javascript/app.vue
<Root>
Why list component not found ? I imported it successfully and have name for it.
As @skirtle suggested, I added console.log and found that tag was unclosed