Vue js + Rails 6 - 未知的自定义元素: <list>



我有一个新的Rails 6应用程序,带有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>

和app/javascript/list.vue组件:

<template>
<div>
I am List Component
</div>
</template>
<script>
export default {
name: 'list',
data: function () {
return {
posts: []
}
}
}
</script>

和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)
})

但在浏览器中我得到错误

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>

为什么找不到列表组件?我成功地导入了它,并为它命名。

正如@skirtle所建议的,我添加了console.log,发现标签未关闭

最新更新