问题
I am trying to replicate the vue tutorial example (found here: https://v3.vuejs.org/guide/component-basics.html#passing-data-to-child-components-with-props ), but with no success. Below is my code. I have a view called TA.vue, that i would like to import the component into and render. Any ideas what I am doing wrong?
TA.vue (the view):
<template id="front">
<b-container style="margin-top: 9rem;">
<b-row>
<div id="blog-posts-events-demo" class="demo">
<div>
<blog_post
v-for="post in posts"
:key="post.id"
:title="post.title"
></blog_post>
</div>
</div>
</b-row>
</b-container>
</template>
<script>
import blog_post from '../components/blog_post' // import the Header component
export default {
name: 'talent-acquisition',
components: {
blog_post
},
data() {
return {
posts: [
{ id: 1, title: 'My journey with Vue'},
{ id: 2, title: 'Blogging with Vue'},
{ id: 3, title: 'Why Vue is so fun'}
]
}
},
}
</script>
blog_post component:
Vue.component('blog_post', {
props: ['title'],
template: `
<div class="blog_post">
<h4>{{ title }}</h4>
</div>
`
})
app.mount('#blog-posts-events-demo')
Full error message:
vue.runtime.esm.js?2b0e:619 [Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <BlogPost>
<TalentAcquisition> at src/views/TA.vue
<App> at src/App.vue
<Root>
回答1:
Your blog_post
file is using CDN syntax instead of CLI syntax and so isn't exporting a component. Additionally, it tries to mount an entirely new Vue app.
Since you're using Vue CLI with single file components, all your components need to have a similar format to your TA.vue component. So blog_post
should look like this:
<template>
<div class="blog_post">
<h4>{{ title }}</h4>
</div>
</template>
<script>
export default {
props: ['title']
}
</script>
来源:https://stackoverflow.com/questions/65746235/failed-to-mount-component-template-or-render-function-not-defined-component-fa