【问题标题】:VueJS error: "Failed to mount component: template or render function not defined"VueJS 错误:“无法挂载组件:未定义模板或渲染函数”
【发布时间】:2018-06-07 12:04:01
【问题描述】:

我很难理解 VueJS 中的组件和模板系统。我下载了VuetifyJS PWA example template 并尝试将Hello.vue 的完整内容替换为VuetifyJS google-contacts.vue 示例模板的内容。 我在npm run devlocalhost:8080 后收到此错误消息:

> vue.esm.js?65d7:578 [Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <Hello> at /home/a/my-project/src/components/Hello.vue
       <App> at /home/a/my-project/src/App.vue
         <Root>

为什么不能只替换 &lt;template&gt;&lt;/template&gt; 内容,我需要更改什么才能使用 google-contacts.vue 模板内容而不是 Hello.vue 内容?

【问题讨论】:

  • 据我所见,处理 Vue 组件通常有两种方式:1) 使用组件的 template 属性的经典方式,以及 2) 导出单个组件和然后稍后导入它们。听起来第二个是你的目标,你做错了。不幸的是,我们无法确定是否是这种情况。请提供代码 sn-ps,以便我们更清楚地了解您的问题。
  • 我链接了我在问题中使用的代码(粗体文本)和完整的模板。 (这些都是 VuetifyJS 的例子)
  • @ramazan793 我尝试了建议的解决方案,但没有奏效。错误:&lt;hello&gt; - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in ---&gt; &lt;App&gt; at /home/a/my-project/src/App.vue &lt;Root&gt;
  • @Tom 尝试在 main.js 中全局注册您的组件:import Hello from '~/components/hello.vue' Vue.component('Hello', Hello); 与该问题的第二个答案一样

标签: vue.js vuejs2 vue-component vuetify.js


【解决方案1】:

我只是按照这个过程进行的,它对我来说没问题,所以我猜这很可能是你的构建中的一个错误步骤,但到目前为止无法重现它。

注意,看起来docs/examples/layouts/google-contacts.vue 是整个页面布局的替代品,而不是单个组件(按照@B.Fleming 在 cmets 中提到的思路思考),因此替换App.vue 比替换@987654323 更合适@。

这是我最初所做的(没有彻底阅读您的帖子)。但随后替换 Hello.vue 给了我相同的工作 Google 联系人页面。

【讨论】:

  • 这是一个构建问题。谢谢
猜你喜欢
  • 2018-07-16
  • 2020-02-02
  • 2017-02-13
  • 2019-07-02
  • 1970-01-01
  • 2017-10-20
  • 2017-02-25
  • 2023-03-24
  • 2020-06-14
相关资源
最近更新 更多