无法安装组件:模板或渲染函数未定义。组件导入失败

2024-05-06

我正在尝试复制 vue 教程示例(在这里找到:https://v3.vuejs.org/guide/component-basics.html#passing-data-to-child-components-with-props https://v3.vuejs.org/guide/component-basics.html#passing-data-to-child-components-with-props),但没有成功。下面是我的代码。我有一个名为 TA.vue 的视图,我想将组件导入并渲染。有什么想法我做错了吗?

TA.vue(视图):

<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 组件:

Vue.component('blog_post', {
    props: ['title'],
    template: `
        <div class="blog_post">
            <h4>{{ title }}</h4>
        </div>
    `
})

app.mount('#blog-posts-events-demo')

完整错误消息:

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>

Your blog_post文件使用 CDN 语法而不是 CLI 语法,因此不会导出组件。此外,它还尝试安装一个全新的 Vue 应用程序。

由于您将 Vue CLI 与单文件组件一起使用,因此所有组件都需要具有与您的组件类似的格式TA.vue成分。所以blog_post应该看起来像这样:

<template>
  <div class="blog_post">
    <h4>{{ title }}</h4>
  </div>
</template>
<script>
export default {
  props: ['title']
}
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法安装组件:模板或渲染函数未定义。组件导入失败 的相关文章

随机推荐