Vue js + Rails 6 - 未知自定义元素:<list>
Vue js + Rails 6 - Unknown custom element: <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,发现标签未关闭
我有新鲜的 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,发现标签未关闭